Skip to content

Instantly share code, notes, and snippets.

@mfontani
Created June 28, 2011 16:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 "###"
@akeeton
Copy link

akeeton commented Mar 20, 2020

What an amazing script!

@mfontani
Copy link
Author

mfontani commented Mar 20, 2020

What an amazing script!

@aketoon
I've a few more on https://git.marcofontani.it/mfontani/scripts https://github.com/mfontani/los-opinionated-git-tools and https://github.com/mfontani/git-recent -- if you're into git, linux, and doing more with less ;) Hope this helps!

@akeeton
Copy link

akeeton commented Mar 20, 2020

It would be amazing-er if it could work with any branch, not just master. Unfortunately, git plumbing is not my forte.

@akeeton
Copy link

akeeton commented Mar 20, 2020

@mfontani I'll be sure to check those out, thanks!

@mfontani
Copy link
Author

It would be amazing-er if it could work with any branch, not just master. Unfortunately, git plumbing is not my forte.

I'm sure I've updated this script since to take an optional branch as parameter, I'll dig it and update this gist. Check back ~Monday.

@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