When I do a git rebase and I get a conflict, I can use git log (or my preferred improved git log) which shows me all the commits thus far. However, I often get confused about what the current commit is that caused the conflict.
It would be super helpful if I could see the commit message of the current (incomplete) commit.
Update If you are running Git 2.17 or newer, it turns out you can view the current commit in the ongoing rebase with
git rebase --show-current-patch
If you are running an older version of Git you can use this
git show $(more $(git rev-parse --git-path REBASE_HEAD))
How the Older Version Works
The remainder of this article explores how the pre-Git 2.17 command from above works.
Manually
When a rebase is occurring, in the Git directory (i.e. .git/
) a file is created called REBASE_HEAD
, which contains a single line of text which is the SHA of the current (incomplete) commit.
We could open .git/REBASE_HEAD
, make note of the SHA (e.g. abc123abc123abc123
), and then view that commit with
git show abc123abc123abc123
Automated
The manual process to view this information is a lot of work, which is why I prefer the one line automated method.
git show $(more $(git rev-parse --git-path REBASE_HEAD))
To understand this we’re going to start with the inner most section and work our way out.
git rev-parse –git-path
git rev-parse --git-path REBASE_HEAD
git rev-parse –git-path returns the path to the given Git file relative to our current directory.
From the root of our project
git rev-parse --git-path REBASE_HEAD
.git/REBASE_HEAD
from a subdirectory in our project
git rev-parse --git-path REBASE_HEAD
../.git/REBASE_HEAD
Bash Command Substitution
Command substitution lets us take the output of a command and use it as part of another command.
If we are in the root of our git project
more $(git rev-parse --git-path REBASE_HEAD)
is the same as
more .git/REBASE_HEAD
both output the SHA of the current (incomplete) commit in the rebase.
more $(git rev-parse --git-path REBASE_HEAD)
abc123abc123abc123
Git Show
We want to view the commit (e.g. abc123abc123abc123
)
git show abc123abc123abc123
We can do this by adding another level of command substitution, since
more $(git rev-parse --git-path REBASE_HEAD)
gives us abc123abc123abc123
we get
git show $(more $(git rev-parse --git-path REBASE_HEAD))
It might be worth mentioning
git rebase –show-current-patch
Thanks Tom, you’re right
wasn’t on my radar and it is a much better solution (when available). I’ve updated this article with that as the first suggestion. Thanks for introducing me to this command.
̀`git show REBASE_HEAD` should just work, no? and then you can use whatever format you want, i.e. `git show –format= REBASE_HEAD`.