gor*_*rds 19 git gitignore git-config
我想忽略分支中的某些文件,而不必依赖在.gitignore与其他分支合并期间将被覆盖的跟踪文件.
我一直密切关注Stack Overflow的回答以及链接的博客帖子,但我的回购似乎并没有认识到excludesfile我的指定.git/config.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
.gitignore我的"specialbranch"中没有文件.
如果我试图忽略像这样的文件info.php,我的.git/info/exclude_specialbranch文件看起来像这样:
info.php
...但它不会忽略该文件.
如果我运行git status --ignored,它只列出.DS_Store默认exclude文件中的文件.
但是,如果我添加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
它完全忽略了文件.
请注意,没有线仍然工作excludesfile = +/info/exclude在[core]在.git/config.Git似乎知道系统范围在哪里,exclude我不必告诉它.
我有一种感觉,.git/config即无法识别我的自定义排除文件的地址:
excludesfile = +/info/exclude_specialbranch
...很可能是因为使用了+描述.git目录的位置.
在(最近的)Git版本中解决自定义排除文件的正确方法是什么?
我正在运行OSX 10.9.5和Git 2.2.1版.
Pal*_*lec 28
你正在努力实现Git不支持的东西.该博客文章是这个骗局是原始出处堆栈溢出的答案只能人云亦云.正如在该答案的评论中所指出的那样,即使是最初的博客文章也包含了一些讨论,该讨论表明该解决方案不起作用,并且它链接到更新的博客帖子,该帖子提到甚至作者也无法重现该行为.
为什么它不起作用?如果你读man gitignore和man git-config,你会发现只是core.excludesfile引用.没有branch.<name>.excludesfile.这core.excludesfile意味着您可以排除例如Vim .swp文件或您的软件使用的其他临时内容.
core.excludesfile除了
.gitignore(每个目录)之外.git/info/exclude,Git 还会查看此文件中的文件模式,这些文件不是要跟踪的."~/"扩展为指定用户主目录的值$HOME和"~user/".它的默认值是$XDG_CONFIG_HOME/git/ignore.如果$XDG_CONFIG_HOME未设置或为空,$HOME/.config/git/ignore则使用.见gitignore(5).
我相信每个分支排除文件的最佳近似值是使用post-checkout钩子实现的,并.gitignore通过符号链接实现.
每个分支将具有例如.gitignores具有以相应分支命名的文件的目录.然后会有一个.gitignores/__default默认使用的文件.该.gitignore会由所有不包括文件被排除在外,并将由结账后钩的符号链接到相应的文件被创建.gitignores.
如果您不想跟踪排除文件,则可以使用.git/info/exclude文件作为符号链接.git/info/excludes/__default等来执行相同操作.
| 归档时间: | 
 | 
| 查看次数: | 9307 次 | 
| 最近记录: |