How do I git blame without seeing merges

ε祈祈猫儿з 提交于 2019-12-07 10:06:51

问题


If I've got a file whose history is like this:

----A----B
     \    \
      C----D----E

and I do a blame from E then I'd like to see what changed in revisions B & C, but I don't really care about D, since that was a merge.

Is there a way I can do this? I guess I'm looking for some kind of --no-merges option to git blame, but I'm not seeing one in the manual.


回答1:


Actually, you do care about D. Consider this case:

in commit B:
2) banana
3) coconut
4) domino     // conflicts with C

in commit C:
2) banana
3) coconut
4) elephant   // conflicts with B

In commit D, we resolve the conflict:

in commit D:
2) banana
3) coconut
4) domino-elephant

Notice that in D, a line appears which didn't appear in either B or C. If you ignore merges, you would never see that, and you'd never be able to tell where line 4 came from, which is bad.




回答2:


An alternative is to use git log -L start,end:filename which shows (by default, the complete) history of the line or lines numbered between start and end in filename. You can also use git log -L /regex/,/regexend/:filename to identify lines by a regex instead of by line numbers. By its nature you will probably get different results than with git blame in many cases, but I was able to find the "real" (i.e. non-merge) change more conveniently than with git blame.



来源:https://stackoverflow.com/questions/5290094/how-do-i-git-blame-without-seeing-merges

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!