【问题标题】:Git warning "encountered old-style '/home/user/.gitignore' that should be '%(prefix)/home/user/.gitignore'"Git 警告 \"encountered old-style \'/home/user/.gitignore\' that should be \'%(prefix)/home/user/.gitignore\'\"
【发布时间】:2023-02-18 01:53:52
【问题描述】:

使用 git 版本 2.35.1.windows.2,所有 Git 调用至少包含一次此警告:

PS C:\Users\BoppreH\Desktop\source\keyboard> git status
warning: encountered old-style '/home/boppreh/.gitignore' that should be '%(prefix)/home/boppreh/.gitignore'
On branch new_core
Your branch is up to date with 'origin/new_core'.
[...]

有时多次:

PS C:\Users\BoppreH\Desktop\source\keyboard> git pull
warning: encountered old-style '/home/boppreh/.gitignore' that should be '%(prefix)/home/boppreh/.gitignore'
warning: encountered old-style '/home/boppreh/.gitignore' that should be '%(prefix)/home/boppreh/.gitignore'
warning: encountered old-style '/home/boppreh/.gitignore' that should be '%(prefix)/home/boppreh/.gitignore'
warning: encountered old-style '/home/boppreh/.gitignore' that should be '%(prefix)/home/boppreh/.gitignore'
warning: encountered old-style '/home/boppreh/.gitignore' that should be '%(prefix)/home/boppreh/.gitignore'
Already up to date.

这令人困惑,因为我在 Windows 上并且我的主文件夹中没有 .gitignore 文件。

是什么导致了这个警告?

【问题讨论】:

    标签: git


    【解决方案1】:

    对于 Windows 的最新 git 版本,建议在任何根文件引用前加上 %(prefix)

    否则你会得到你所指的警告。您获得它的次数取决于您运行的git 命令。这有效地反映了 .gitconfig 文件中此类引用被解析的次数。

    我相信如果您按如下方式更新有问题的行,您将不会收到警告消息。

    [core]
       excludesfile = %(prefix)/home/boppreh/.gitignore
    

    顺便说一句,Git for Windows v2.35.3 在使用适用于 Linux 的 Windows 子系统 (WSL) 时发布了与 %(prefix) 相关的错误修复。

    如果您添加前缀并且您仍然收到警告,则可能与您的情况有关。

    【讨论】:

      【解决方案2】:

      ~/.gitconfig 的用户配置文件包含以下条目:

      [core]
          excludesfile = /home/boppreh/.gitignore
      

      所以问题是我假设前导斜杠使路径成为绝对路径(它没有),并且我从没有匹配的 .gitignore 文件的 Linux 机器传输了一个 .gitconfig 文件。

      我的解决方案是删除违规行。

      【讨论】:

        【解决方案3】:

        文件名中的一个简单的~ 为我解决了这个问题,还有一个额外的好处,它可以在 Windows 和 Unix 上运行。

        [core]
          excludesfile = ~/.gitignore
        

        警告应该消失了。

        【讨论】:

          【解决方案4】:

          尝试一下:

          git config --global --unset-all safe.directory
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-11-11
            • 1970-01-01
            • 2019-10-22
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-07-14
            • 2019-04-27
            相关资源
            最近更新 更多