在删除文件的情况下进行 merge 后,“git log -- file_name”没有显示当前分支的提交。但是,如果我执行“git log”或“git log --first-parent -- file_name”,则会显示提交。为什么?
重新创建的步骤:
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 ***
我认为 log 命令的 --first-parent 版本会显示第一个 log 命令列出的提交的子集,但事实并非如此。
最佳答案
我的猜测是默认的History Simplification算法意识到,更改与来自 master 的 merge 无关。如果您明确关闭简化,您将得到您所期望的结果:
git log --full-history -- file1.txt # Shows commit with ***
关于git - "git log -- file_name"显示小于 "git log --first-parent -- file_name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28610078/