2

It seems git log --follow always ignore all the merge commits even though the merge commit include some content change different from its parents.

I just use two different branches from master to change the same file and merge them back with --no-ff. Since two branch change the same file, the later merge conflict. And I just combine the change from the two branch. However, when I try to inspect the change history. I find that "git log" list the latter merge commit as expected. However, "git log --follow" just ignore all merge commit even latter merge actually change some content.

My git version is 2.19.1.windows.1.

My Operating System is windows 10.

My problem could be reproduce with following commands:

# init git repository
git init .

# create a.txt 
echo Hello > a.txt
git add a.txt
git commit -m "First commit"

# change a.txt in branch ch1
git checkout -b ch1
echo World >> a.txt
git commit -am "first change"

# change a.txt in branch ch2
git checkout master
git checkout -b ch2
echo Git >> a.txt
git commit -am "second change"

# merge ch1 back into master with no-ff
git checkout master
git merge --no-ff ch1

# merge master into ch2 and resolve conflict
git checkout ch2
git merge master

echo "Hello
World
Git" > a.txt

git commit -a

# merge ch2 back into master with no-ff
git checkout master
git merge --no-ff ch2

Then, in master branch when I run git log --oneline --graph -- a.txt, I just get:

*   4506bb4 (ch2) Merge branch 'master' into ch2
|\
| * 09c2898 (ch1) first change
* | 0c7e2e6 second change
|/
* 0363441 First commit

When I run git log --oneline --graph --follow -- a.txt, I just get:

...
| * | 09c2898 (ch1) first change
|/ /
| * 0c7e2e6 second change
|/
* 0363441 First commit

I just expect the same log history with or without --follow option in this simple scenario. Why git log --follow seems always ignore the merge commits even though the merge commit actually include some change different from its parent?

Alex
  • 43
  • 5
  • 2
    Not exactly a duplicate, but see https://stackoverflow.com/q/48814114/1256452 -- you're being bitten by History Simplification, which is slightly different with `--follow` turned on. Note that in your case, the merge commit is "not TREESAME" to either parent, so `git log` follows both by default. With `--follow` it winds up stripping the merge and getting confused. – torek Aug 12 '19 at 09:30
  • 1
    @torek Thanks for your comments. It's a good explanation for `git log`. So it's true that `git log --follow` ignores the merge commits which is checked by `git log` command? Is there any option to get the ''not TREESAME" merge commits back with `--follow` option? – Alex Aug 12 '19 at 14:11
  • Well, in this case `--follow` is not doing anything for you so you can just omit it. It's also not clear *why* it is damaging the graph the way it does. But if you have a case where `--follow` *does* do something for you (because a file is renamed), the way that `--follow` is implemented—as a cheesy hack, really—makes it not very useful. The internal algorithm needs to be rewritten. – torek Aug 12 '19 at 15:20
  • @torek Thanks for your clarification. Surely I use `--follow` option to find rename in my real project. I find the merge commits missing problem with `--follow` option. I just try to make the problem scenario more concentrated and clearer as above. – Alex Aug 12 '19 at 15:41

0 Answers0