我希望在一个分支中忽略某些文件,而不必依赖于被其他分支合并时会被覆盖的已跟踪的.gitignore
文件。
我已经仔细遵循了Stack Overflow回答以及链接的博客文章,但是我的仓库似乎没有识别到我在.git/config
中指定的excludesfile
。Git文档(git-config
,gitignore
)似乎没有显示如何为特定分支指定和处理排除文件。
我的.git/config
如下所示:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
excludesfile = +/info/exclude
[branch "myspecialbranch"]
excludesfile = +/info/exclude_specialbranch
我的 .git/info/exclude
文件看起来像这样(默认情况下,我没有修改它):
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.DS_Store
在我的“specialbranch”分支下,我没有一个.gitignore
文件。
如果我试图忽略一个名为info.php
的文件,那么我的.git/info/exclude_specialbranch
文件看起来像这样:
info.php
...但它不会忽略该文件。
如果我运行git status --ignored
,它只会列出默认exclude
文件中的.DS_Store
文件。
然而,如果我将info.php
添加到我的.git/info/exclude
文件中:
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.DS_Store
info.php
它完全忽略了该文件。
请注意,在.git/config
的[core]
下没有excludesfile = +/info/exclude
这一行,它仍然能正常工作。Git似乎知道系统范围内的exclude
在哪里,而无需我告诉它。
我有一种感觉,.git/config
没有识别出我的自定义排除文件的地址:
excludesfile = +/info/exclude_specialbranch
很可能是由于使用+
来描述.git
目录的位置。
在Git的(最新)版本中,如何正确地处理自定义排除文件?
我正在运行OSX 10.9.5和Git版本2.2.1。
branch.<name>.excludesfile
。 - Palec