List merge commits affecting a file

[亡魂溺海] 提交于 2019-12-02 18:06:12

The problem in your case is that the merge commits are empty, because you take stuff only from one branch, so git simplifies history by removing those "empty" commits.

So to have your merge commits shown in the log, you need to tell git to change history simplification, by telling --simplify-merges. If you want to understand why you have to use this, go ahead in the git log man page, but I'm out of it :) Anyway in this case the merge commit is correctly shown with a.txt filtering, so that's what you want.

Finally, you want to show diff two times, with each parent, with -m.

So this gives

git log -U -m --simplify-merges --merges -- a.txt

with output

commit a7340d6e91deedff6f52c8ec8da932245f73e5f6 (from d577e6c4dcbff5485ded666c89f38
Merge: d577e6c fe3c4d2

    merge commit

diff --git a/a.txt b/a.txt
index 319137b..1aa6dc4 100644
--- a/a.txt
+++ b/a.txt
@@ -1,3 +1,2 @@
 First
-Second: main-branch
-Third: main
+Second: on branch1

You can add the --merges to the log command. This will only list merge commits. Further, you can specify --first-parent so that you only follow the branch history and not consider the history of branches merged into it.

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