Git show the conflicting commit during a rebase

To view the failed patch’s commit you can use the following bash function:

function show_patch() {
  git show $(head -1 .git/rebase-apply/${1} | awk '{ print $2 }')

Put it in your .bash_profile or similar.

Example useage:

show_patch 0001

Copy the patch number from git’s output message e.g. “Patch failed at 0001″

2 thoughts on “Git show the conflicting commit during a rebase

  1. Thanks for this. I did a little further digging and found that you can avoid having to enter the patch number by looking at the first line of the .git/rebase-apply/patch file. Try this command:

    git show `head -n 1 .git/rebase-apply/patch`

  2. This was super handy, thanks!

    One thing that caught me out is that if you run this anywhere but the top level, you end up showing HEAD instead of the patch revision, which is pretty misleading. I added in a call to rev-parse to find .git from any subdirectory, add added it as an alias:
    git config –global alias.showrebase ‘!git rev-parse –git-dir| xargs -I{} head -n 1 {}/rebase-apply/patch | xargs git show’

    Then, as long as you’re anywhere in the repo you can see .git/rebase-apply/patch with:

    git show-rebase

    and compare the results to

    git diff –cached

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>