7

Given the following (slightly contrived) situation - 3 commits with their commit messages, where I'm 2 commits ahead of my origin/master and want to rebase:

C1   <-- origin/master
  first commit

  * Implement the foo

C2
  second commit

  * Wibble the foo
  * This is temporary to workaround the issue with the thingy, and can be removed after Steve applies his fix.

C3   <-- HEAD
  third commit

  * Add the wotsit

With C3 checked-out, I do: git rebase origin/master, and let's say there's a conflict, so I see something like:

First, rewinding head to replay your work on top of it...
Applying: second commit
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging foo.txt
CONFLICT (add/add): Merge conflict in foo.txt
error: Failed to merge in the changes.
Patch failed at 0001 C2
The copy of the patch that failed is found in: .git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

At this point, git log will show me all the commits prior to the one that caused the conflict, up to C1:

$ git log
commit C1
Author: Me
Date:   Thu Oct 26 16:12:53 2017 +0100

    first commit

    * Implement the foo

commit C0
Author: Someone else
Date:   Wed Oct 25 ...

    etc...

To help give me context about which commit it is that I'm currently looking at, I'd like to see the full message for the commit that I'm currently rebasing.

In this case that's the message for commit C2, which reminds me that I can safely git rebase --skip this commit, as my change was a temporary workaround that I want to throw away anyway.

The message telling you about the conflict only gives the first line of the message "second commit", not the body with the useful bullet points.

Is that possible? I can see that it might be weird because, at the point where I'm in the middle of the rebase, the commit doesn't really exist yet, but equally the message must exist somewhere, because when I resolve the conflict and do git rebase --continue, the original commit message will be applied.

DaveyDaveDave
  • 9,821
  • 11
  • 64
  • 77
  • `git show C2` won't cut it? – kostix Oct 31 '17 at 15:32
  • @kostix - I think it probably would, but the challenge there is that, at the point where the rebase is telling you that there's a conflict, it only gives you the first line of the commit message that it's trying to apply, so you don't actually see "C2" at that point, and you'd have to go a long way around to find it. – DaveyDaveDave Oct 31 '17 at 15:59
  • 1
    Looks like I have managed to find [the answer](https://stackoverflow.com/a/2118461/720999). Looks a bit hacky (implementation-dependent) but still better than nothing. Oh, and [this one](https://makandracards.com/makandra/13011-git-in-an-interactive-rebase-find-out-which-commit-you-are-currently-working-on-until-version-1-7-9-5) is even more interesting. (JFTR I've googled [this](https://www.google.com/search?q=git+sha1+of+commit+rebase+stopped+at)). – kostix Oct 31 '17 at 16:33
  • 1
    Plain (non-interactive, no extra flags) `git rebase` actually uses `git format-patch` to turn the original commit series into patches followed by `git am` to apply the patches. This makes it annoyingly difficult to figure out which patch is failing. See the answers in @kostix's comment; note that the format of `.git/rebase-apply/` has evolved over time, so some of this is Git-version-dependent. Using interactive rebase makes Git run `git cherry-pick`, which makes it easier to see what's being cherry-picked since that's now in `CHERRY_PICK_HEAD`. – torek Oct 31 '17 at 17:18
  • @kostix - you're absolutely right - thank you. I'll flag this as a duplicate linking to that answer. In fact, the file `.git/rebase-apply/0001` actually contains the message as well as the patch. – DaveyDaveDave Oct 31 '17 at 20:47
  • I landed here via google, I guess `git log -1 C2` should work. It would also be nice to be to do something like `git rebase --show-current-commit` or `git rebase --show --stat` etc. – Devin Rhode Jul 31 '23 at 18:49

1 Answers1

0

So, you want to see the commit message that caused the conflict. Well, you could do interactive rebase. It always shows the commit id and name for which the conflict occurs as an error.

git rebase -i <other_branch>
hspandher
  • 15,934
  • 2
  • 32
  • 45
  • @DaveyDaveDave Ok, I get it now. Have you tried interactive rebasing. It shows the commit message, whenever a conflict happens, and you can do lot of other stuff with it as well like squashing commits or rewriting history. `git rebase -i` – hspandher Oct 31 '17 at 15:44
  • Hmm, that's close to what I'm looking for, but I just tried it, and (unless I'm missing something) it only shows the first line of the commit message; if there's detail in the body of the message, it's lost. – DaveyDaveDave Oct 31 '17 at 16:03