如何解决全局.gitignore无效
即使配置看起来不错,我也无法让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
的所有目录及其中的文件。当我在存储库中的.gitignore中添加行.vscode/
时,此方法非常有效。但是,它在全局文件中无效:
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。
解决方法
Git for Windows希望使用反斜杠指定路径:
git config --global core.excludesFile "C:\\Users\\UserXYZ\\.gitignore_global"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。