简体   繁体   English

Git:显示单个文件的历史记录,包括合并提交

[英]Git : show history of a single file, including merge commits

TL;DR : is there a way to list all commits that modified a single file, including merge commits ? TL; DR:有没有办法列出所有修改单个文件的提交,包括合并提交? Knowing that git log -p --cc {filename} as suggested here does not do the trick. 知道这里建议的git log -p --cc {filename}并不能解决问题。


In the following scenario : 在以下情况下:

  • master, branch1 and branch2 exists 主,branch1和branch2存在
  • commit C1 introduces a change in branch1 提交C1在branch1中引入了更改
  • commit M1 merges branch1 into master 提交M1将branch1合并到master
  • master is merged into branch2, but there are conflicts, and the merger accidentally breaks some of the changes introduced by C1 ; master被合并到branch2中,但是存在冲突,并且合并意外破坏了C1引入的某些更改; so we end up with a merge commit M2, that creates a broken branch2 所以我们最终得到一个合并提交M2,它创建了一个损坏的branch2
  • commit M3 merges branch2 into master, thus breaking master 提交M3将branch2合并到master,从而破坏master

I understand this scenario is bad news (there should have been automated tests to realize branch2 was broken, and M3 should have never happen in the first place, etc... Back to the sad reality of people being people and screwing up sometimes.) 我知道这种情况是个坏消息(应该有自动化测试才能发现branch2坏了,而M3从来就不会发生,等等……回到人们成为人们的悲伤现实,有时会搞砸了。)

We had a hard time realizing this, because, althought we knew exactly what file caused the error, we did not find a way to list all the commits. 我们很难实现这一点,因为尽管我们确切地知道是什么文件导致了错误,但是我们没有找到列出所有提交的方法。

Following this SO question, we tried : 按照这个SO问题,我们尝试了:

git log -p --cc {filename}

This only prints commits up to C1. 这只会打印提交到C1的提交。

What are we missing ? 我们缺少什么? Thanks. 谢谢。

我会尝试这样的:

git log -m --no-max-parents -p {filename}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM