0

If a file's history includes a merge commit with an "interesting" conflict resolution, git log will skip over it. Why is this, and how can I make that commit be included?

(By "interesting", I mean a resolution that doesn't just take the version from HEAD or MERGE_HEAD verbatim.)

For example, in this sample repository, I've prepared a simple history that illustrates the problem:

$ git log --oneline --graph 
* 4a69f452 add -stuff at C and G
*   9fc8e8bf resolve E-alpha + E-beta as E-gamma
|\  
| * 95bc62e9 add -beta suffix on lines E and J
* | 465abd9e add -alpha suffix on lines A and E
|/  
* f43dc68c initial ten-line A..J file

The merge commit resolved the conflict by introducing an entirely new version of the E line:

$ git show 9fc8e8bf -U0 | grep -A100 ^@@
@@@ -5,1 -5,1 +5,1 @@@
- E-alpha
 -E-beta
++E-gamma

However, git log totally glosses over this. The commits it lists fail to explain the current state of the E line in test.txt:

$ git log --oneline 4a69f452 test.txt
4a69f452 add -stuff at C and G
95bc62e9 add -beta suffix on lines E and J
465abd9e add -alpha suffix on lines A and E
f43dc68c initial ten-line A..J file

Is there an option I can give to git log that will make it include the merge commit?

Other commands, like git blame, do show that the E line was last touched in the 9fc... merge commit:

$ git blame -L5,5 4a69f452 test.txt
9fc8e8bf9 (Matt McHenry 2016-12-28 16:55:10 -0500 5) E-gamma

(Note: the above outputs are produced by git version 2.11.0.)

Matt McHenry
  • 20,009
  • 8
  • 65
  • 64
  • Which version of Git are you using? Using 2.7.4, `git log --oneline 4a69f452 test.txt` shows the `9fc` commit for me. – K. A. Buhr Dec 28 '16 at 22:32
  • 1
    Add `--cc` and `git log` will look at a combined-diff and should find the change. I'm not sure why the default options are the way they are. (They seem to vary a bit from one Git version to another, and when I try your example, cloned from your GitHub link, in 2.10.1, I see the `9fc` commit.) – torek Dec 28 '16 at 22:59
  • @torek you're right, `--cc` does make it pick up that commit. Despite it being listed in the "Diff Formatting" section of the man page, which makes it sound as though it should *not* impact the commits included in the log! Do you get the merge commit even without `--cc` in `2.10.1`? – Matt McHenry Dec 29 '16 at 01:13
  • I updated the question to include the version of git I'm using, `2.11.0`. – Matt McHenry Dec 29 '16 at 01:15
  • 2
    I do see that commit, without `--cc`, in 2.10.1. (I had to explicitly `git checkout` something—I think it was `gamma`—first, so that Git could find the file.) BTW, see https://github.com/git/git/commit/82dee4160cc6d1b0d792c9f07b5803cd42abc610 - it looks as though before 2.6.0 you had to use an explicit `-m`. I'm also not sure why I see it without `--cc` myself, since without one of the various options, Git has that "ignore merges" flag set. – torek Dec 29 '16 at 02:00
  • 1
    Ah, `-m` *also* makes the merge commit appear for me. It's *really* misleading that these options are in the "Diff Formatting" section of the man page ... have I said that yet? :) – Matt McHenry Dec 29 '16 at 03:12
  • I cannot recreate this behaviour. I've tried Git v1.7.6, v2.11.0, and v2.7.4, and they all output the correct list with "git log --oneline 4a69f452 test.txt". I'm on Ubuntu. – G. Sylvie Davies Dec 29 '16 at 20:08
  • Thanks to the "works for me" reports from @K.A.Buhr, @torek, and @G.SylvieDavies, I tried this on another machine known to be running an identical `git` binary, and couldn't reproduce it. That led me to comparing the `~/.gitconfig` files and finding the issue. – Matt McHenry Jan 03 '17 at 02:17

1 Answers1

0

This happens if you have the log.follow config option set to true or, equivalently, if you pass --follow to the log command.

The documentation for this option says it "does not work well on non-linear history". I guess this is what they mean. :(

$ git log --oneline 4a69f452 -- test.txt
4a69f45 add -stuff at C and G
9fc8e8b resolve E-alpha + E-beta as E-gamma
95bc62e add -beta suffix on lines E and J
465abd9 add -alpha suffix on lines A and E
f43dc68 initial ten-line A..J file

$ git log --oneline 4a69f452 --follow -- test.txt
4a69f45 add -stuff at C and G
95bc62e add -beta suffix on lines E and J
465abd9 add -alpha suffix on lines A and E
f43dc68 initial ten-line A..J file
Matt McHenry
  • 20,009
  • 8
  • 65
  • 64