git - "git log -- file_name"显示小于 "git log --first-parent -- file_name"

标签 git git-log

在删除文件的情况下进行 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/

相关文章:

git - 查看 merge 提交的补丁

git - stash 后出现的 'WIP' 和 'index' 提交是什么?

Git 仓库创建者姓名

git - VS 2017 - 团队资源管理器提交 - 快捷方式

windows - 在 Windows 上使用单个命令通过 git log 获取第一行

git-branch - git:列出悬挂标签

git - 将上游新分支推送到原点

Git post-receive Hook 将每个分支 checkout 到不同的文件夹?

git - TeamCity 在一个 Git 存储库上卡在 "Updating sources"

Git merge 冲突 : Cannot find the problem