如何查看 Git 合并冲突的“三向差异”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18131515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I see a "three way diff" for a Git merge conflict?
提问by Nathan Long
Suppose I'm on Git branch master
and I git merge featurebranch
. There is a conflict in foo.html
.
假设我在 Git 分支上master
,我git merge featurebranch
. 中存在冲突foo.html
。
When I open foo.html
, I see, in the area of the conflict, what master
has and what featurebranch
has. But I can't really tell what changewas made on master
that conflicted with featurebranch
; I only know what master has now.
当我打开 时foo.html
,我会看到在冲突区域中的内容master
和内容featurebranch
。但我真的不知道在与;冲突的地方做了什么改变;我只知道主有现在。master
featurebranch
I'd like to see the diffthat each one applied.
我想看看每个应用的差异。
Or, to get the same information, I could see:
或者,为了获得相同的信息,我可以看到:
- The version
master
has now - The version
featurebranch
has now - The version their common ancestorhad
- 现在版本
master
有 - 现在版本
featurebranch
有 - 该版本他们共同的祖先有
How can I see this?
我怎么能看到这个?
回答by RazerM
From git-merge(1),
An alternative style can be used by setting the "merge.conflictstyle" configuration variable to "diff3".
In addition to the
<<<<<<<
,=======
, and>>>>>>>
markers, it uses another|||||||
marker that is followed by the original text. ... You can sometimes come up with a better resolution by viewing the original.
可以通过将“merge.conflictstyle”配置变量设置为“diff3”来使用替代样式。
除了
<<<<<<<
,=======
和>>>>>>>
标志,它使用另一个|||||||
后跟原文标记。...您有时可以通过查看原件获得更好的分辨率。
This can be enabled using
这可以使用启用
git config --global merge.conflictstyle diff3
or right in ~/.gitconfig
file
或在~/.gitconfig
文件中
[merge]
conflictstyle = diff3
回答by Nathan Long
A lot of GUI diff/merge tools have a 3 or 4 way merge view. I highly recommend Beyond Comparefor resolving merge conflicts. Another (okay) tool is DiffMerge.
许多 GUI 差异/合并工具都有 3 或 4 路合并视图。我强烈推荐Beyond Compare来解决合并冲突。另一个(好的)工具是DiffMerge。
You can set up a custom mergetool to use with the git mergetool
command. This is my .gitconfig
configuration for Beyond Compare (Pro edition) and DiffMerge on my Windows machine using msysgit:
您可以设置自定义合并工具以与git mergetool
命令一起使用。这是我.gitconfig
在 Windows 机器上使用 msysgit 对 Beyond Compare(专业版)和 DiffMerge 的配置:
[merge]
tool = bc3
[diff]
tool = bc3
[difftool "dm"]
cmd = C:/Program\ Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\"
[difftool "bc3"]
cmd = "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\""
[mergetool "bc3"]
cmd = "\"c:/program files (x86)/beyond compare 3/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\""
You can read more about various diff/merge tool configurations in the official Linux Kernel Git documentation for git config
.
您可以在官方 Linux 内核 Git 文档中git config
阅读有关各种差异/合并工具配置的更多信息。