Git 警告“遇到旧式‘/home/user/.gitignore’,应该是‘%(prefix)/home/user/.gitignore’”

Bop*_*reH 24 git

使用 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'.
[...]
Run Code Online (Sandbox Code Playgroud)

有时多次:

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.
Run Code Online (Sandbox Code Playgroud)

.gitignore这很令人困惑,因为我使用的是 Windows,并且我的主文件夹中没有文件。

是什么导致了这个警告?

Ioa*_*tis 15

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

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

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

[core]
   excludesfile = %(prefix)/home/boppreh/.gitignore
Run Code Online (Sandbox Code Playgroud)

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

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


mar*_*cra 6

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

[core]
  excludesfile = ~/.gitignore
Run Code Online (Sandbox Code Playgroud)

警告应该消失了。