【发布时间】:2023-03-11 02:23:01
【问题描述】:
即使配置看起来不错,我也无法让 git 使用我的 .gitignore_global 文件:
PS C:\path\to\repository> git config --global core.excludesfile
C:/Users/UserXYZ/.gitignore_global
PS C:\path\to\repository> git config core.excludesfile
C:/Users/UserXYZ/.gitignore_global
PS C:\path\to\repository> type C:/Users/UserXYZ/.gitignore_global
# ignore settings for VSCode
.vscode/
所以 git 应该忽略所有名称为 .vscode 的目录以及其中的文件。当我将行 .vscode/ 添加到存储库中的 .gitignore 时,这非常有效。但是对全局文件没有影响:
PS C:\path\to\repository> git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: generic/somefile.cpp
Untracked files:
(use "git add <file>..." to include in what will be committed)
.vscode/
generic/.vscode/
simulator/.vscode/
no changes added to commit (use "git add" and/or "git commit -a")
如果我将该行添加到存储库内的 .gitignore 中,未跟踪的文件就会消失。 我也在使用 sourcetree,但我认为这不相关,因为通过命令行的行为完全相同。
感谢您的帮助!
编辑:引号与否,斜杠或反斜杠(单或双),这一切似乎都没有什么区别。我的 .gitconfig 看起来像这样,它也不起作用:
[user]
name = Full Name
email = full.name@example.com
[difftool "sourcetree"]
cmd = 'C:/Program Files/Perforce/p4merge.exe' \"$LOCAL\" \"$REMOTE\"
[mergetool "sourcetree"]
cmd = 'C:/Program Files/Perforce/p4merge.exe' \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
trustExitCode = true
[core]
excludesFile = "C:\\Users\\UserXYZ\\.gitignore_global"
我的 git 版本是2.28.0.windows.1。
更新: 好吧,这是一个棘手的问题。事实证明,我的常规 .gitignore 中有一个部分使全局文件无效(即使配置正确):
#binary ignore pattern
*
!/**/
!*.*
如果我理解正确,首先忽略所有内容,然后带回所有目录和所有带扩展名的文件(包括我想在 global_gitignore 中引入的那些)。所以现在的问题是一个稍微不同的问题:有没有办法从我的全局 .gitignore 中覆盖它?我无法在项目级别更改 .gitignore。
【问题讨论】:
-
检查以确保您的全局忽略文件是纯文本、UTF-8(无 BOM)文件。 Windows 喜欢编写 UTF-16-LE 文件,而 Git 不理解这些。
-
谢谢@torek,我检查过了,文件已经保存为UTF-8(没有BOM)。
-
很好奇。在这一点上,它似乎应该工作。该行在本地文件中有效,设置正确...
标签: git gitignore atlassian-sourcetree