Did Git change the “!” prefix behavior at .gitignore?

不打扰是莪最后的温柔 提交于 2020-08-05 04:16:06

问题


I found a below sentence in Git 2.7 Release Notes.

  • Allow a later "!/abc/def" to override an earlier "/abc" that appears in the same .gitignore file to make it easier to express "everything in /abc directory is ignored, except for ...".

    Git 2.7 Release Notes

However, This function seems to be invalid in subsequent versions.

$ git --version
git version 2.19.1
$  cat .gitignore
/abc
!/abc/def
$ mkdir abc
$ echo foo > abc/def
$ git status
On branch master
nothing to commit, working tree clean

Did Git change the "!" prefix behavior at .gitignore? Or did I mistake?


回答1:


It looks like that change was reverted in 2.8.0, why are you combing two-year-old release notes to see how gitignore behaves when you could just say git help ignore and it'd tell you

  • An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined. Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "!important!.txt".

The easy way to do your gitignores if you don't want the ignored-directory pruning is to ignore their entire contents with

directory/**

follwed by any overrides, (e.g. your !directory/def) and at the end of your gitignore put

!*/

followed by any complete exclusions you really meant for effect.



来源:https://stackoverflow.com/questions/53753201/did-git-change-the-prefix-behavior-at-gitignore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!