【问题标题】:Unable to reset git template path [duplicate]无法重置 git 模板路径 [重复]
【发布时间】:2021-04-05 08:09:41
【问题描述】:

Git 正在读取一个陈旧的模板路径。这条路径曾经在我的旧 VM 中。我已将这个 git 目录原样复制到一个新的虚拟机中。 我尝试从~/.gitconfig 中删除“[commit] 模板”条目,然后是git commit,但它仍然给我这个错误。 然后我尝试删除所有条目,但无济于事。

$ git config --global --unset-all commit.template
$ git commit
fatal: could not read '/home/subtleseeker/main/commit-template.txt': No such file or directory

知道吗,git 是从哪里读取这条路径的?

$ git config --global commit.template /home/peeches/main/commit-template.txt
$ git config -l | grep template
commit.template=/home/peeches/main/commit-template.txt
commit.template=/home/subtleseeker/main/commit-template.txt
$ git config --global --unset-all commit.template
$ git config -l | grep template
commit.template=/home/subtleseeker/main/commit-template.txt

Git 版本:git version 2.30.1 操作系统:CentOS Linux release 7.9.2009 (Core)

【问题讨论】:

    标签: git


    【解决方案1】:

    配置是本地的

    commit.template=/home/peeches/main/commit-template.txt
    commit.template=/home/subtleseeker/main/commit-template.txt
    

    这显示了两个条目,git checks/outputs config in the following order:

    读取时,默认从系统、全局和存储库本地配置文件中读取值

    根据问题中的输出顺序,不需要的配置条目来自本地存储库的 git config。

    因此,要删除该引用,请从本地配置中删除:

    $ git config --unset commit.template
    

    注意:--local 标志可以指定为显式 - 但这是写入操作 (see the docs for more info) 的默认行为,因此没有必要。

    尽管实际上有more places git checks for config:

    • $(prefix)/etc/gitconfig
    • $HOME/.config/git/config
    • ~/.gitconfig
    • $GIT_DIR/config
    • $GIT_DIR/config.worktree(仅在启用extensions.worktreeConfig 时)

    如果有疑问,请依次检查。

    复制

    考虑:

    $ git init
    Initialized empty Git repository in /tmp/so/.git/
    ➜  so git:(master) git config some.thing=local
    error: invalid key: some.thing=local
    ➜  so git:(master) git config some.thing local
    ➜  so git:(master) git config --global some.thing global
    ➜  so git:(master) git config -l | grep some.thing
    some.thing=global
    some.thing=local
    ➜  so git:(master)
    

    这模拟了问题中的情况。移除全局配置,不影响本地配置:

    ➜  so git:(master) git config --global --unset-all some.thing
    ➜  so git:(master) git config -l | grep some.thing
    some.thing=local
    ➜  so git:(master)
    

    但更新本地配置会:

    ➜  so git:(master) git config --unset some.thing
    ➜  so git:(master) git config -l | grep some.thing
    ➜  so git:(master)
    

    【讨论】:

      猜你喜欢
      • 2011-01-08
      • 1970-01-01
      • 2018-09-24
      • 2021-05-20
      相关资源
      最近更新 更多