你如何让 git diff 在 OS X 上使用 gitx --diff

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/736911/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:38:18  来源:igfitidea点击:

How do you make git diff use gitx --diff on OS X

gitmacosdiff

提问by BJ Clark

Gitx has a great diff viewer, how do I make git automatically pipe git diff whateverinto gitx?

Gitx有很大的差异阅读器,我怎么做自动混帐管git的差异无论到gitx?

I've tried to set git config diff.external to a shell script that looks like this:

我尝试将 git config diff.external 设置为如下所示的 shell 脚本:

git diff "" "" | gitx

However, that only opens all the individual files up into multiple gitx windows, and it really messes up the files names (changes them all to tmp files with crazy names).

但是,这只会将所有单个文件打开到多个 gitx 窗口中,并且确实弄乱了文件名(将它们全部更改为具有疯狂名称的 tmp 文件)。

Does anyone have a better solution?

有没有人有更好的解决方案?

回答by Wolfram Kriesing

like sigjuice is saying up there. Only that noobs (like i am now) need to know how to "connect" git to use it. Here is what I did

就像 sigjuice 所说的那样。只有那些菜鸟(就像我现在一样)需要知道如何“连接”git 才能使用它。这是我所做的

echo 'opendiff  ' > ~/opendiff-git.sh
chmod a+x ~/opendiff-git.sh
git config --global diff.external ~/opendiff-git.sh 

and now all "git diff whatever" should open FileMerge.app ...

现在所有“git diffwhatever”都应该打开 FileMerge.app ...

回答by jonalv

I am not quite sure this is what you want but for us on Macs it sure is handy anyway and somewhat related, you might want to try:

我不太确定这是否是您想要的,但对于我们在 Mac 上的应用,它确实很方便,并且有些相关,您可能想尝试:

$ git difftool -t opendiff #hash

$ git difftool -t opendiff #hash

That opens the diff in the opendiff program which I find very useful. This is much easier than creating a shell script and forcing all your diffs through the new external diff. If you are not on a Mac you can probably change the opendiff into your favorite available diff tool...

这会在 opendiff 程序中打开差异,我觉得这非常有用。这比创建 shell 脚本并通过新的外部差异强制所有差异要容易得多。如果您不在 Mac 上,您可能可以将 opendiff 更改为您最喜欢的可用差异工具...

回答by sigjuice

I'm sorry this doesn't really answer your question about gitx. I'm not even sure if gitx can function as a generic diff tool. You might like FileMerge, a merge/diff tool included in the Xcode install. There is a script called opendiff that can launch it for you. Simply make a script with the following line in it and point diff.external at it.

很抱歉,这并没有真正回答您关于 gitx 的问题。我什至不确定 gitx 是否可以用作通用 diff 工具。您可能喜欢 FileMerge,它是 Xcode 安装中包含的合并/差异工具。有一个名为 opendiff 的脚本可以为您启动它。只需在其中创建一个包含以下行的脚本并将 diff.external 指向它。

opendiff  

回答by Mark

I did this for Araxis merge, but modifying these basic instructions should not be hard for whatever you perferred tool is.

我为 Araxis 合并做了这个,但是无论你喜欢什么工具,修改这些基本指令都不难。

First I created ~/bin/git-diff-driver.sh and added execute permission to the file.

首先,我创建了 ~/bin/git-diff-driver.sh 并为该文件添加了执行权限。


#!/bin/sh

/usr/local/bin/compare -title1:" (repo version)" -title2:" " -max "" ""

Araxis installs it's command line interface tools in /usr/local/bin The compare tool is their generic tool and the araxis* tools feed through compare.

Araxis 将其命令行界面工具安装在 /usr/local/bin 中。比较工具是他们的通用工具,araxis* 工具通过比较提供。

Once this is set up the following lines need to be added to ~/.gitconfig

设置完成后,需要将以下几行添加到 ~/.gitconfig


[merge]
    tool = araxismerge
[mergetool "araxismerge"]
    cmd = "/usr/local/bin/compare -3 -merge -wait $LOCAL $BASE $REMOTE $MERGED"
    path = /usr/local/bin/
[diff]
    external = "/Users/mark/bin/git-diff-driver.sh"

This redirects all 2-way and 3-way diffs through Araxis Merge. It seems like the "path =" shouldn't be necessary, but it works.

这通过 Araxis Merge 重定向所有 2 向和 3 向差异。似乎“路径=”不应该是必需的,但它有效。

Good Luck.

祝你好运。

回答by Douglas

I'm using this script which I have named git-diffxand put in my path:

我正在使用我命名git-diffx并放在我的路径中的这个脚本:

#!/bin/bash

result=$(git diff $@)

if [ "$result" ]; then
   echo "$result" | gitx
fi

Then instead of git diff ..., you call git diffx ....

然后git diff ...,您调用git diffx ....

回答by tek_yogi

This question might be a little old, but I just found something that works for me.

这个问题可能有点老了,但我刚刚找到了对我有用的东西。

Open GitX app(v.7), select "GitX" menu then "Enable Terminal Usage"

打开 GitX 应用程序(v.7),选择“GitX”菜单,然后选择“启用终端使用”

At terminal pipe diff to gitx via:

在终端管道 diff 到 gitx 通过:

git diff | gitx

混帐差异| gitx

回答by Rob Wilkerson

I asked a similar questiona while back. That answer may help you. There are a couple of questions in there, but one has to do with opening a diff view in something other than FileMerge.

不久前我问了一个类似的问题。这个答案可能对你有帮助。那里有几个问题,但一个与在 FileMerge 以外的其他东西中打开差异视图有关。