简体   繁体   中英

How to show merge commit in git log <file>?

I happened to run into a situation when a merge can effectively roll back a commit without any log traceable in any easy way I know of:

*   fcfea4c merge   code.txt:1                       other.txt:a
|\
| * b0f6762 conflict code.txt:1                      other.txt:b
* | 9fe5de2 other  code.txt:2                       other.txt:a
|/
* e0d9522 previous   code.txt:1
* 7a466e5 init    touch code.txt

The left branch is master and the right branch is feature , when merging in fcfea4c , there is a conflict in file other.txt (code.txt should be automaticlly merged by git), and if I run git checkout HEAD~ . (e0d9522 previous commit) at master and then conclude commit. git log code.txt will only show init(7a466e5) and previous(e0d9522) commit and the other(9fe5de2) commit is missing. So is there a easy way to trace what happened to code.txt (show other and merge commits as well)?

You should try instead:

git checkout --ours -- others.txt

That should preserve the history of the merge while keeping the content you are after.

git log --first-parent --graph --all -- code.txt是答案,-- --first-parent实际上意味着将合并视为该特定分支上的常规提交( Follow only the first parent commit upon seeing a merge commit. )。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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