gpt4 book ai didi

git - 如何告诉 git 忽略全局配置

转载 作者:行者123 更新时间:2023-12-04 01:45:36 27 4
gpt4 key购买 nike

The Git docs谈论默认的全局 git 配置文件位置($XDG_CONFIG_HOME/git/config~/.gitconfig),但不提供告诉 git 命令的方法忽略该文件。

我正在寻找一个环境变量,可能称为 $GIT_CONFIG_NOGLOBAL (类似于 $GIT_CONFIG_NOSYSTEM ),或传递给 git 命令的标志(例如 --ignore-global -配置)。我需要它是因为我的标准 git 设置(尤其是 commit.gpgsign true)会干扰使用 git 的测试套件。

如果目前不可能,我可以在他们的问题跟踪器上提出问题。

最佳答案

使用 Git 2.32(2021 年第二季度)的另一种方法是使用新的 GIT_CONFIG_SYSTEM:

Git 2.32 用 GIT_CONFIG_SYSTEM 替换 GIT_CONFIG_NOSYSTEM 机制以拒绝读取系统范围的配置文件,让用户指定从哪个文件读取系统范围的配置文件配置(将其设置为空文件本质上与设置 NOSYSTEM 相同),并引入 GIT_CONFIG_GLOBAL 以覆盖 $HOME/.gitconfig .

commit 482d549 (2021 年 4 月 23 日)和 commit 4179b48 , commit 1e06eb9 , commit c62a999 (2021 年 4 月 19 日)作者:Patrick Steinhardt (pks-t) .
(由 Junio C Hamano -- gitster -- 中的 commit e706aaf merge ,2021 年 5 月 7 日)

config: allow overriding of global and system configuration

Signed-off-by: Patrick Steinhardt

In order to have git run in a fully controlled environment without any misconfiguration, it may be desirable for users or scripts to override global- and system-level configuration files.
We already have a way of doing this, which is to unset both HOME and XDG_CONFIG_HOME environment variables and to set GIT_CONFIG_NOGLOBAL=true.
This is quite kludgy, and unsetting the first two variables likely has an impact on other executables spawned by such a script.

The obvious way to fix this would be to introduce GIT_CONFIG_NOGLOBAL as an equivalent to GIT_CONFIG_NOSYSTEM.
But in the past, it has turned out that this design is inflexible: we cannot test system-level parsing of the git configuration in our test harness because there is no way to change its location, so all tests run with GIT_CONFIG_NOSYSTEM set.

Instead of doing the same mistake with GIT_CONFIG_NOGLOBAL, introduce two new variables GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM:

  • If unset, git continues to use the usual locations.
  • If set to a specific path, we skip reading the normal configuration files and instead take the path.
    By setting the path to /dev/null, no configuration will be loaded for the respective level.

This implements the usecase where we want to execute code in a sanitized environment without any potential misconfigurations via /dev/null, but is more flexible and allows for more usecases than simply adding GIT_CONFIG_NOGLOBAL.

git config 现在包含在其 man page 中:

GIT_CONFIG_GLOBAL

GIT_CONFIG_SYSTEM

Take the configuration from the given files instead from global orsystem-level configuration.

git 现在包含在它的 man page 中:

GIT_CONFIG_GLOBAL

GIT_CONFIG_SYSTEM

Take the configuration from the given files instead from global orsystem-level configuration files. If GIT_CONFIG_SYSTEM is set, thesystem config file defined at build time (usually /etc/gitconfig)will not be read. Likewise, if GIT_CONFIG_GLOBAL is set, neither$HOME/.gitconfig nor $XDG_CONFIG_HOME/git/config will be read. Canbe set to /dev/null to skip reading configuration files of therespective level.


例如,baltakatei the comments 中提及, 可能在 this context :

Running export GIT_CONFIG_GLOBAL=''; export GIT_CONFIG_SYSTEM='' before running make allowed me to compile a program that expects git log -1 --pretty=oneline somefile to get a commit hash when I have log.showsignature=true in my ~/.gitconfig file.
(git log-1 --pretty=oneline can print more than one line depending on what's in gitconfig files).
Context: compiling Kaldi, a speech transcription program.

关于git - 如何告诉 git 忽略全局配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43881807/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com