Skip to content

Instantly share code, notes, and snippets.

@mietek
Created July 3, 2013 12:58
Show Gist options
  • Save mietek/5917659 to your computer and use it in GitHub Desktop.
Save mietek/5917659 to your computer and use it in GitHub Desktop.
Better git diff for branches which had stuff merged in
# Example:
#
# giterdun 339f7db..6ed04fa
# git diff | $EDITOR
# BRANCH=`git rev-parse --abbrev-ref HEAD` && git checkout . && git checkout master && git branch -D $BRANCH
giterdun()
{
RANGE=$1
SHAS=`git log --no-merges --first-parent --pretty=%h --reverse $RANGE`
if [ $? -ne 0 ]; then
return 1
fi
BEGIN=`echo $RANGE | sed 's/\.\..*$//'`
END=`echo $RANGE | sed 's/^.*\.\.//'`
BRANCH=`uuidgen`
echo "Branching $BRANCH off $BEGIN..."
git checkout -q $BEGIN
git checkout -qb $BRANCH
for SHA in $SHAS; do
echo "Applying $SHA..."
git show -p $SHA | git apply
if [ $? -ne 0 ]; then
git show -p $SHA
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment