• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / View Current Commit Message during Git Rebase Conflict
Boy looking through binoculars.

View Current Commit Message during Git Rebase Conflict

Last updated on January 17, 2021 by Sal Ferrarello

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))

Photo Credit

George Hodan

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Dev Tips, Solution Tagged With: Git, rebase

Reader Interactions

Comments

  1. Tom says

    July 23, 2020 at 8:55 am

    It might be worth mentioning

    git rebase –show-current-patch

    Reply
    • Sal Ferrarello says

      September 29, 2020 at 6:33 am

      Thanks Tom, you’re right

      git rebase --show-current-patch

      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.

      Reply
  2. Phil says

    November 26, 2020 at 6:57 pm

    ̀`git show REBASE_HEAD` should just work, no? and then you can use whatever format you want, i.e. `git show –format= REBASE_HEAD`.

    Reply

Leave a Reply Cancel reply

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

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in