为什么不`git diff`调用外部diff工具? [英] Why doesn't `git diff` invoke external diff tool?

查看:165
本文介绍了为什么不`git diff`调用外部diff工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的存储库中,如果我键入

In my repository, if I type

$ git diff some-file

$ git difftool some-file

我得到终端内差异显示。我认为这不应该发生,因为我已经设置了一个外部diff工具,如 git config -l <​​/ code>的输出所示:

I get the in-terminal diff display. I think this should not happen, because I have set up an external diff tool, as shown by the output of git config -l:

$ git config -l
user.name=blah blah
user.email=blah blah
http.sslverify=true
diff.external=/home/daniel/bin/git-diff  <--This is the important line
push.default=simple
core.filemode=false
core.editor=gedit
alias.tree=log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)
         %C(black)[%cr]%C(reset)  %x09%C(black)%an: %s %C(reset)'
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
remote.origin.url=https://daniel@skynet/git/pyle.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.daniel.remote=origin
branch.daniel.merge=refs/heads/daniel

diff.external line看起来像这样

The git-diff file referenced in the diff.external line looks like this

#!/bin/bash

meld $2 $5

为什么没有 git diff invoke meld?

Why doesn't git diff invoke meld?

如果我设置了一些行为,使得 git config -l <​​/ code>具有以下行:

I get the same behaviour if I set things up so that git config -l has the following line:

diff.tool = meld

diff.external = usr/bin/meld

注意:我机器上的其他存储库不存在此问题。

Note: Other repositories on my machine don't have this problem.

相关但不等同于SO问题:

Related, but not equivalent, SO questions:


  1. git diff 和<$>之间的区别是什么? c $ c> git difftool

  2. 无法让git diff使用外部diff工具的diff.external

  1. What is the difference between git diff and git difftool?
  2. Cannot make git diff use diff.external for external diff tool


推荐答案


我得到终端内差异显示。我不应该这样做,因为我设置了一个外部差异工具

I get the in-terminal diff display. I this should not happen, because I have set up an external diff tool

是的,它应该:diff.external in-terminal diff display。

Yes, it should: diff.external is for "in-terminal diff display".

(from git config 手册页

(from git config man page)

diff.external




如果这个配置变量已设置,差异生成不是使用内部差异机制执行的,而是使用给定命令

可以用 GIT_EXTERNAL_DIFF 覆盖c $ c>环境变量。

使用git(1)中的git Diffs中所述的参数调用该命令。注意:如果您只想在文件的子集上使用外部差异程序,则可能需要使用 gitattributes(5)

If this config variable is set, diff generation is not performed using the internal diff machinery, but using the given command.
Can be overridden with the GIT_EXTERNAL_DIFF environment variable.
The command is called with parameters as described under "git Diffs" in git(1). Note: if you want to use an external diff program only on a subset of your files, you might want to use gitattributes(5) instead.

问题链接解释了为什么 meld 无法扮演外部差异的角色。

The question you link explains why meld wouldn't be able to play the role of an "external diff".

使用其他工具在视觉上查看差异是通过以下方式完成的:

Viewing a diff visually with another tool is done with:

git difftool --dir-diff shaOfHisCheckIn^!
git difftool --tool=meld --dir-diff shaOfHisCheckIn^!
git difftool -t meld -d shaOfHisCheckIn^!

meld 可以在Windows上配置为difftool:请参阅 Windows上的Git Diff和Meld

meld can be configured on Windows as a difftool: see "Git Diff and Meld on Windows".

如果你想为git diff配置meld,你可以(在Ubuntu上)使用 diff.external ,但是使用包装脚本

If you wanted to configure meld for git diff, you could (on Ubuntu) use the diff.external, but with a wrapper script:


使用以下命令创建一个名为 git-diff.sh 的文件内容:

create a file called git-diff.sh, using the following content:



#!/bin/bash
meld "$2" "$5" > /dev/null 2>&1




将它保存到一个位置例如 / usr / local / bin ,并赋予它可执行的权限:

Save this to a location such as /usr/local/bin, giving it executable rights:



$ sudo mv git-diff.sh /usr/local/bin/
$ sudo chmod +x /usr/local/bin/git-diff.sh




最后一步是打开 $ HOME / .gitconfig 文件并添加以下几行:

The final step is to open your $HOME/.gitconfig file and add the following few lines:



[diff]
        external = /usr/local/bin/git-diff.sh




下次在Git项目中输入git diff并进行更改时,Meld将启动,向您显示拆分窗格差异查看器。

请注意,您需要先关闭meld的打开实例下一个差异查看器打开。

The next time you type git diff in a Git project with changes, Meld will be launched showing you a split-pane diff viewer.
Note that you are required to close the open instance of meld before the next diff viewer is opened.

这篇关于为什么不`git diff`调用外部diff工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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