Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

git - 如何解决Git中的合并冲突(How to resolve merge conflicts in Git)

如何解决Git中的合并冲突?

  ask by Spoike translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try: git mergetool

(尝试: git mergetool)

It opens a GUI that steps you through each conflict, and you get to choose how to merge.

(它会打开一个GUI,逐步引导您解决每个冲突,然后您可以选择如何合并。)

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:

(根据@JoshGlover评论:)

The command doesn't necessarily open a GUI unless you install one.

(除非您安装一个GUI,否则该命令不一定会打开GUI。)

Running git mergetool for me resulted in vimdiff being used.

(为我运行git mergetool导致使用了vimdiff 。)

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 .

(您可以安装以下工具之一,而不是使用它: meldopendiffkdiff3tkdiffxxdifftortoisemergegvimdiffdiffuseecmergep4mergearaxisvimdiffemerge 。)

Below is the sample procedure to use vimdiff for resolve merge conflicts.

(以下是使用vimdiff解决合并冲突的示例过程。)

Based on this link

(基于此链接)

Step 1 : Run following commands in your terminal

(第1步 :在终端中运行以下命令)

git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompt false

This will set vimdiff as the default merge tool.

(这会将vimdiff设置为默认的合并工具。)

Step 2 : Run following command in terminal

(第2步 :在终端中运行以下命令)

git mergetool

Step 3 : You will see a vimdiff display in following format

(步骤3 :您将看到以下格式的vimdiff显示)

  ╔═══════╦══════╦════════╗
  ║       ║      ║        ║
  ║ LOCAL ║ BASE ║ REMOTE ║
  ║       ║      ║        ║
  ╠═══════╩══════╩════════╣
  ║                       ║
  ║        MERGED         ║
  ║                       ║
  ╚═══════════════════════╝

These 4 views are

(这4个视图是)

LOCAL – this is file from the current branch

(本地–这是当前分支中的文件)

BASE – common ancestor, how file looked before both changes

(BASE –共同祖先,两次更改之前文件的外观)

REMOTE – file you are merging into your branch

(远程–将文件合并到分支中)

MERGED – merge result, this is what gets saved in the repo

(已合并-合并结果,这就是保存在存储库中的内容)

You can navigate among these views using ctrl + w .

(您可以使用ctrl + w在这些视图之间导航。)

You can directly reach MERGED view using ctrl + w followed by j .

(您可以使用ctrl + wj直接进入MERGED视图。)

More info about vimdiff navigation here and here

(有关此处此处的 vimdiff导航的更多信息)

Step 4 .

(第四步 。)

You could edit the MERGED view the following way

(您可以通过以下方式编辑MERGED视图)

If you want to get changes from REMOTE

(如果您想从REMOTE获得更改)

:diffg RE  

If you want to get changes from BASE

(如果要从BASE获得更改)

:diffg BA  

If you want to get changes from LOCAL

(如果您想从本地获得更改)

:diffg LO 

Step 5 .

(步骤5 。)

Save, Exit, Commit and Clean up

(保存,退出,提交和清理)

:wqa save and exit from vi

(:wqa保存并退出vi)

git commit -m "message"

git clean Remove extra files (eg *.orig) created by diff tool.

(git clean删除由diff工具创建的多余文件(例如* .orig)。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...