When to use leading slash in gitignore

前端 未结 2 830
悲哀的现实
悲哀的现实 2020-12-22 17:50

I\'m trying to understand more clearly the .gitignore syntax, and in particular as far as https://github.com/github/gitignore gitignores are concerned.

相关标签:
2条回答
  • 2020-12-22 18:12

    You've answered your own question entirely. If you look at the github/gitignore repo more closely, you'll see most files use inconsistent rules about how patterns are written; it's very likely most were contributed by people who didn't bother to read the documentation nor test things out as you did.

    So if that helps: You're right, be confident.

    If you see mistakes in collaborative projects such as this, don't hesitate to contribute your knowledge. There's even some precedent if you need to build up your confidence further.

    0 讨论(0)
  • 2020-12-22 18:21

    Just wanted to summarize for possible quick future reference -- the leading slash anchors the match to the root. Thus, in the example below, without the slash, the wildcard would also exclude everything within foo because it would take * and move recursively down the tree. However, with /*, it excludes everything except folder foo and its contents:

    $ cat .gitignore
    /*
    !/foo
    
    0 讨论(0)
提交回复
热议问题