Merging With a GUI

源自:http://www.gitguys.com/topics/merging-with-a-gui/


Merging With a GUI



Commands discussed in this section:

  • git mergetool

Merging With a GUI

Git can also work with a large number of GUI tools for helping with merging. A couple of popular GUI tools used on Linux are kdiff3 and meld. They are worth trying (you may need to install them if they aren’t installed yet).

Back To The Same Old Conflict

We’ll go back to the conflict in the the second line of the README file, from our repository as described in the Merging Branches With a Conflict page.

Merging with kdiff3

If you want to try out kdiff3 you could type:

$ git mergetool -t kdiff3
Merging the files: README

Normal merge conflict for 'README':
  {local}: modified
  {remote}: modified
Hit return to start merge resolution tool (kdiff3):

kdiff3

You can see 3 windows at the top and a large window on the bottom in the kdiff3 GUI. The 3 windows on the top, from left to right are:

  • The common ancestor version
  • The current branch (master)
  • The other branch (test)

The large window on the bottom is editable and is where the result of the merge is placed. kdiff3 makes merging easy. You can put your mouse over the Merge Conflict text and press the right mouse button, which will let you choose which version of text you want:

kdiff3select

You can then choose what you would like for the merge. For example, if you chose Select Line(s) from B, the window at the bottom with the merge result is changed to this:

kdiff3select B

When you are satisifed with the merged version of README, you can click on File–>Save and exit and then resolve the conflict by adding README to the index.

Merging with meld

If you want to try to use meld you can type:

$ git mergetool -t meld
Merging the files: README

Normal merge conflict for 'README':
  {local}: modified
  {remote}: modified

Hit return to start merge resolution tool (meld):

You would then see:

meld

With meld, three windows are shown, and left to right are:

  • The local branch (master branch)
  • The current version that you are merging into

    The other (or “remote”) version (from the test branch)

To choose the text from the master branch, click on the black arrow in the left-most window at the top right. The resulting merge looks like this:

meld1

Clicking on a black arrow moves text to other file (meld copies the text to the other file, and removes the text from where it was). After you have saved the version of README, you can resolve the conflict in git.

Configure Git For Your Mergetool Of Choice

To configure git to remember which merge tool you want, type git config –global merge.tool [tool]. For example, if you want git mergetool to automatically use kdiff3 as our mergetool, we would type:

$ git config --global merge.tool kdiff3

There are many merge tools available and everybody has their own favorites.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值