Skip to content

Instantly share code, notes, and snippets.

@mfontani
Created June 28, 2011 16:46
Show Gist options
  • Save mfontani/1051568 to your computer and use it in GitHub Desktop.
Save mfontani/1051568 to your computer and use it in GitHub Desktop.
git-rr: show which files were changed in commits, when rebasing
#!/bin/sh
# Usage:
# Once you started git rebase --interactive master, and you are presented
# with the list of commit SHAs and commit messages, from Vim:
# - visually select all SHAs via "V}k"
# - launch git-rr: !git-rr
# - ...
# - profit! you now have the same info as before, just with the list of
# filenames which changed with each commit, and can now move around
# commits knowing which files were touched by which commit
# Get current branch, without initial "heads/"
BRANCH=$(git describe --all | perl -lne's!^heads/!!;print')
# Kill the "git log" paging features
PAGER=
# Lines look like:
# * c0ffee00 commit message1
# path/to/file1
# <-= newline
# * 00c0ffee commit message2
# path/to/file2
# <-= newline
echo "### START Rebasing branch $BRANCH"
echo "###"
git log --reverse --pretty=format:'* %h %s' --abbrev-commit --stat --name-only master.. | perl -lne'
if ( m!^\*! ) {
s!^\*!pick ! # by default, show "pick"
} else {
s!^!# ! # just comment-out anything else, with leading spaces for filenames
}
s!\s*$!!; # kill any trailing spaces
print
'
echo "###"
echo "### END Rebasing branch $BRANCH"
echo "###"
@mfontani
Copy link
Author

@akeeton see https://github.com/mfontani/los-opinionated-git-tools/blob/master/git-rr just updated with the bits which make it work properly both with a given branch/sha, and with the configuration to do the right thing automatically from a git rebase -i, if one's using vim as their editor. Hope this helps!

@cfconrad
Copy link

inspired from your script, I did it this way: https://github.com/cfconrad/scripts/blob/master/git/git-rb

It's basically the same, but I do not get the list of commits again, while just parsing the current buffer from stdin...
With this, I don't care about branches --autosqash or rebase.instructionFormat, cause I just don't touch it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment