git - 无法理解 Git 的 difftool 配置是如何设置的

标签 git macos difftool

我需要在我的旧 Git 中使用与以下类似的设置才能使用 difftool。设置不完全相同,因为我不小心删除了旧的 .gitconfig。

 [merge]
     tool=opendiff

 [mergetool]
     tool=opendiff

 [difftool]
     difftool=opendiff

我家里有一个空的 .gitconfig。 我仍然可以使用 opendiff -工具。 这是一个惊喜,因为这应该是不可能的。

Git 的 difftool 设置在内部如何工作?

最佳答案

你可以看到一个complete setup using mergetool and difftool here .

如果设置似乎仍然有效,可能是因为它已在全局或您的帐户中设置,因为 git-config 将在三个文件中搜索配置选项:

$GIT_DIR/config

存储库特定的配置文件。 (文件名当然是相对于存储库根目录,而不是工作目录。)

~/.gitconfig

用户特定的配置文件。也称为 Git 安装位置的“全局”配置文件:

$(prefix)/etc/gitconfig

系统范围的配置文件。


Git 会在您输入“git config”时保存用户信息:

来自 git config manual page :

The file-option can be one of --system, --global or --file which specify where the values will be read from or written to.
The default is to assume the config file of the current repository, .git/config unless defined otherwise with GIT_DIR and GIT_CONFIG.

You can override these rules either by command line options or by environment variables. The --global and the --system options will limit the file used to the global or system-wide file respectively.
The GIT_CONFIG environment variable has a similar effect, but you can specify any filename you want.

可能是您在之前的安装中设置了该环境变量?

GIT_CONFIG

从给定文件而不是 .git/config 中获取配置。使用“--global”选项将其强制为 ~/.gitconfig。使用“--system”选项将其强制为 $(prefix)/etc/gitconfig

注意:对于 Mac OsX,$(prefix) 应该是 /usr/local(如果您将 Git 安装为 described here)

make prefix=/usr/local all
sudo make prefix=/usr/local install
which git

关于git - 无法理解 Git 的 difftool 配置是如何设置的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1063618/

相关文章:

apache - 共享 httpd.conf

git - 从 git-gui 调用外部差异工具?

git - 从 git 历史记录中删除文件的某些内容

python - 预接收 Hook 中的 git push 选项

git - 如何使用 git 删除某人对项目的所有贡献?

git difftool 运行 git diff

git - 在外部三向差异工具中查看已提交的 Git merge

git - 为什么 Git 每次推送 origin master 时都会发送整个存储库

macos - 为什么我不能在 ARM64 MacOS 上的 .text 部分组装绝对地址?

python - 我想清理我的 pip/homebrew/python 安装