Git在Windows上:如何设置一个mergetool? [英] Git on Windows: How do you set up a mergetool?

查看:205
本文介绍了Git在Windows上:如何设置一个mergetool?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Cygwin上试过了msysGit和Git。两个工作本身都很好,并且完全运行gitk和git-gui。



现在如何配置一个mergetool? (Vimdiff在Cygwin工作,但最好我想要一些更友好的用户友好的一些我喜欢Windows的同事。)

解决方案

要跟进Charles Bailey的回答,以下是我的git设置,它使用 p4merge (免费跨平台3way合并工具);测试msys Git(Windows)安装:

  git config --global merge.tool p4merge 
git config - 全局mergetool.p4merge.cmd'p4merge.exe \$ BASE\\$ LOCAL \\$ REMOTE \\$ MERGED\'

或者,从Windows cmd.exe shell中,第二行变为:

  git config --global mergetool.p4merge.cmdp4merge.exe \$ BASE\\$ LOCAL \\$ REMOTE \ \\$ MERGED\

更改(相对于Charles Bailey):




  • 添加到全局git config,即对所有git项目有效,而不仅仅是当前的

  • 自定义工具配置值驻留在mergetool。[tool] .cmd,而不是merge。[tool] .cmd(傻,我花了一个小时来解决为什么git不断抱怨不存在的工具)

  • 为所有文件名添加双引号,以便合并工具仍然可以找到具有空格的文件(我在Powershell的msys Git中测试过)

  • 请注意,其安装目录为PATH,因此无需在命令中指定p4merge的完整路径



下载: http://www.perforce.com/product/components/perforce-visual-merge- and-diff-tools






EDIT (2014年2月)



正如 @Gregory Pakosz 指出,最新的 msys git 现在本机支持 p4merge (在 1.8.5.2.msysgit上测试)。

 

您可以通过以下方式显示支持的工具列表: git mergetool --tool-help

您应该看到 p4merge 有效列表中。



如果 p4merge 列为可用,则会显示在您的 > PATH ,您只需要设置 merge.tool

  git config  - -global merge.tool p4merge 

如果列为有效除了 merge.tool ,还必须定义 mergetool.p4merge.path

  git config --global mergetool.p4merge.path c:/Users/my-login/AppData/Local/Perforce/p4merge.exe 




  • 以上是为当前用户安装p4merge而不是系统范围(不需要管理员权限或UAC提升)的示例路径

  • 虽然应该扩展到当前用户的主目录(因此理论上路径应该是〜/ AppData / Local / Perforce /p4merge.exe ),这对我没有用。

  • 更好的是利用环境变量(例如 $ LOCALAPPDATA / Perforce / p4merge.exe ),git似乎没有扩展路径的环境变量(如果你知道如何让这个工作,请让我知道或更新这个答案)


I've tried msysGit and Git on Cygwin. Both work just fine in and of themselves and both run gitk and git-gui perfectly.

Now how the heck do I configure a mergetool? (Vimdiff works on Cygwin, but preferably I would like something a little more user-friendly for some of our Windows-loving coworkers.)

解决方案

To follow-up on Charles Bailey's answer, here's my git setup that's using p4merge (free cross-platform 3way merge tool); tested on msys Git (Windows) install:

git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'

or, from a windows cmd.exe shell, the second line becomes :

git config --global mergetool.p4merge.cmd "p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\""

The changes (relative to Charles Bailey):

  • added to global git config, i.e. valid for all git projects not just the current one
  • the custom tool config value resides in "mergetool.[tool].cmd", not "merge.[tool].cmd" (silly me, spent an hour troubleshooting why git kept complaining about non-existing tool)
  • added double quotes for all file names so that files with spaces can still be found by the merge tool (I tested this in msys Git from Powershell)
  • note that by default Perforce will add its installation dir to PATH, thus no need to specify full path to p4merge in the command

Download: http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools


EDIT (Feb 2014)

As pointed out by @Gregory Pakosz, latest msys git now "natively" supports p4merge (tested on 1.8.5.2.msysgit.0).

You can display list of supported tools by running:

git mergetool --tool-help

You should see p4merge in either available or valid list. If not, please update your git.

If p4merge was listed as available, it is in your PATH and you only have to set merge.tool:

git config --global merge.tool p4merge

If it was listed as valid, you have to define mergetool.p4merge.path in addition to merge.tool:

git config --global mergetool.p4merge.path c:/Users/my-login/AppData/Local/Perforce/p4merge.exe

  • The above is an example path when p4merge was installed for the current user, not system-wide (does not need admin rights or UAC elevation)
  • Although ~ should expand to current user's home directory (so in theory the path should be ~/AppData/Local/Perforce/p4merge.exe), this did not work for me
  • Even better would have been to take advantage of an environment variable (e.g. $LOCALAPPDATA/Perforce/p4merge.exe), git does not seem to be expanding environment variables for paths (if you know how to get this working, please let me know or update this answer)

这篇关于Git在Windows上:如何设置一个mergetool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆