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

发布于 2024-07-26 15:59:43 字数 331 浏览 4 评论 0原文

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

 [merge]
     tool=opendiff

 [mergetool]
     tool=opendiff

 [difftool]
     difftool=opendiff

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

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

I needed to use in my old Git similar settings to the following to be able use difftool. The settings are not exactly the same, since I by accident removed my old .gitconfig.

 [merge]
     tool=opendiff

 [mergetool]
     tool=opendiff

 [difftool]
     difftool=opendiff

I have an empty .gitconfig at Home.
I can use still the opendiff -tool.
This is a surprise, since it should be impossible.

How do Git's difftool settings work internally?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初雪 2024-08-02 15:59:43

您可以看到 使用 mergetool 和 difftool 的完整设置在这里

如果该设置似乎仍然处于活动状态,则可能是因为它已在全局或您的帐户中设置,因为 git-config 将在三个文件中搜索配置选项:

$GIT_DIR/config

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

~/.gitconfig

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

$(prefix)/etc/gitconfig

系统范围的配置文件。


当您键入“git config”时,Git 会在您所说的任何位置保存用户信息:

来自 git 配置手册页

文件选项可以是 --system--global--file 之一,指定值的位置读取或写入。
默认情况下采用当前存储库的配置文件 .git/config ,除非使用 GIT_DIRGIT_CONFIG 另有定义。

您可以通过命令行选项或环境变量覆盖这些规则。 --global--system 选项将分别将使用的文件限制为全局文件或系统范围文件。
GIT_CONFIG 环境变量具有类似的效果,但您可以指定所需的任何文件名。

也许您在之前的安装中设置了该环境变量?

GIT_CONFIG

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

注意:对于 Mac OsX,$(prefix) 应为 /usr/local(如果您将 Git 安装为 此处描述

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

You can see a complete setup using mergetool and difftool here.

If the setting seems to still be active, it may be because it has been set globally or in your account, since there are three files where git-config will search for configuration options:

$GIT_DIR/config

Repository specific configuration file. (The filename is of course relative to the repository root, not the working directory.)

~/.gitconfig

User-specific configuration file. Also called "global" configuration file at your Git's installation location:

$(prefix)/etc/gitconfig

System-wide configuration file.


Git saves the user info wherever you say it to save when you type 'git config':

From 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.

May be you had that environment variable set in your previous installation?

GIT_CONFIG

Take the configuration from the given file instead of .git/config. Using the "--global" option forces this to ~/.gitconfig. Using the "--system" option forces this to $(prefix)/etc/gitconfig.

Note: for Mac OsX, $(prefix) should be /usr/local (if you installed Git as described here)

make prefix=/usr/local all
sudo make prefix=/usr/local install
which git
み零 2024-08-02 15:59:43

您还(除了记住 Git 搜索配置的许多地方之外,如 VonC 的响应)记住,VonC 的响应 html" rel="nofollow noreferrer">git-difftool 和 git-mergetool 提供一些您可以使用的工具的自动检测/自动发现(以某种固定的优先顺序)。

可能就是“git difftool”在您的计算机上调用 opendiff 的原因。

You have also (in addition to remembering about many places Git searches for configuration, as stated in response by VonC) to remember that both git-difftool and git-mergetool provide some autodetection / autodiscovery (in some fixed order of preference) of which tools you have available.

This might be why "git difftool" invokes opendiff on your computer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文