问题描述
解决方案尝试: 有没有一种很好的方法来解释如何解决Git中的合并冲突? > git mergetool
它会打开一个图形用户界面(GUI),引导您完成每个冲突,并选择如何合并。有时候需要稍后手动编辑,但通常本身就足够了。
在@JoshGlover评论中:
命令不一定会打开一个GUI,除非你安装一个。为我运行 git mergetool
导致使用 vimdiff
。您可以安装以下工具之一来使用它: meld
, opendiff
, kdiff3
, tkdiff
, xxdiff
, tortoisemerge
, gvimdiff
, diffuse
, ecmerge
, p4merge
, araxis
, vimdiff
, emerge
。
以下是使用 vimdiff
解决合并冲突的示例过程。基于
第1步:在终端中运行以下命令
git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompt false
这会将vimdiff设置为默认合并工具。
第2步:在终端中运行以下命令
git mergetool
第3步:您将看到以下格式的vimdiff显示:
+ ------- --------------- +
| | | |
| LOCAL | BASE | REMOTE |
| | | |
+ ---------------------- +
|合并|
| |
+ ---------------------- +
这4个视图是
您可以使用这些视图 CTRL + W
。您可以使用 ctrl + w
,然后加上 j
直接进入MERGED视图。
有关vimdiff导航的详细信息和
第4步。您可以通过以下方式编辑MERGED视图
如果您想从REMOTE获得更改
:diffg RE
如果您想从BASE获取更改
:diffg BA
如果您想从本地获得更改
:diffg LO
pre>
第5步。保存,退出,提交和清理
$ b
:wqa
保存并退出vi
git commit -mmessage
git clean
移除diff工具创建的额外文件(例如* .orig)。Is there a good way to explain how to resolve merge conflicts in Git?
解决方案Try:
git mergetool
It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing by hand certainly.
As per @JoshGlover comment:
The command doesn't necessarily open a GUI unless you install one. Running
git mergetool
for me resulted invimdiff
being used. You can install one of the following tools to use it instead:meld
,opendiff
,kdiff3
,tkdiff
,xxdiff
,tortoisemerge
,gvimdiff
,diffuse
,ecmerge
,p4merge
,araxis
,vimdiff
,emerge
.Below is the sample procedure to use
vimdiff
for resolve merge conflicts. Based on this linkStep 1: Run following commands in your terminal
git config merge.tool vimdiff git config merge.conflictstyle diff3 git config mergetool.prompt false
This will set vimdiff as the default merge tool.
Step 2: Run following command in terminal
git mergetool
Step 3: You will see a vimdiff display in following format
+----------------------+ | | | | |LOCAL |BASE |REMOTE | | | | | +----------------------+ | MERGED | | | +----------------------+
These 4 views are
You can navigate among these views using
ctrl+w
. You can directly reach MERGED view usingctrl+w
followed byj
.More info about vimdiff navigation here and here
Step 4. You could edit the MERGED view the following way
If you want to get changes from REMOTE
:diffg RE
If you want to get changes from BASE
:diffg BA
If you want to get changes from LOCAL
:diffg LO
Step 5. Save, Exit, Commit and Clean up
:wqa
save and exit from vi
git commit -m "message"
git clean
Remove extra files (e.g. *.orig) created by diff tool.这篇关于如何解决Git中的合并冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!