Henrik Warne
Henrik Warne

Reputation: 2373

"git log -- file_name" shows less than "git log --first-parent -- file_name"

After doing a merge where a file had been deleted, "git log -- file_name" did not show the commit from the current branch. However, the commit shows up if I do "git log" or "git log --first-parent -- file_name". Why?

Steps to recreate:

git init
echo "First" > file1.txt
git add file1.txt && git commit -m "Adding file1.txt"
echo "Second" > file2.txt
git add file2.txt && git commit -m "Adding file2.txt"
git checkout -b side_branch
echo "... and third" >> file1.txt  # modifying file1.txt in side_branch
git commit -am "*** Adding third to file1.txt in side_branch"
git checkout master
git rm file1.txt && git commit -m "Removing file1.txt in master"
git checkout side_branch
git merge master
git rm file1.txt && git commit --no-edit

git log -- file1.txt                 # Doesn't show commit with *** 
git log                              # Shows commit with *** 
git log --first-parent -- file1.txt  # Shows commit with *** 
git log --follow -- file1.txt        # Shows commit with *** 

I thought that that the --first-parent version of the log command would show a subset of the commits listed by the first log command, but it doesn't.

Upvotes: 2

Views: 125

Answers (1)

Johan Lübcke
Johan Lübcke

Reputation: 20224

My guess is that the default History Simplification algorithm realize that the change is made irrelevant by the merge from master. If you turn off the simplification explicitly you get what you expected:

git log --full-history -- file1.txt     # Shows commit with ***

Upvotes: 3

Related Questions