0

This pattern works properly:

**/Assets/Plugins/Editor/JetBrains*

But this pattern doesn't:

Assets/Plugins/Editor/JetBrains*

As far as I know, these two patterns are equivalent. What might be the problem here?

2
  • Where is your gitignore? in your root folder?
    – CodeWizard
    Dec 9, 2018 at 18:56
  • @CodeWizard yes, it is in the root folder. Dec 9, 2018 at 19:18

2 Answers 2

7

As far as I know, these two patterns are equivalent.

They aren't.

Git has a poorly-documented sneaky feature (bug? annoyance? call it whatever you like, though it's meant as a feature) in which a glob pattern in a .gitignore file is sometimes anchored or rooted—it's not clear what word to use here—and sometimes not. I think this is best explained by example.

Suppose you have the following files:

/a
/b
/dir/a
/dir/b
/dir/sub/a
/dir/sub/b

That is, the top level directory has two files, a and b, and one directory dir. Inside dir there are two files a and b, and another directory sub, and in that last one there are two files a and b.

Listing a in your .gitignore means ignore all files named a,1 so that covers three of the six files.

However, listing /a in your .gitignore means ignore file named a in the top level only, i.e., ignore just one file.

It's the presence of the slash at any position other than the end that triggers this feature, so listing dir/a in your top-level file means ignore file named a in the dir directory only, i.e., just /dir/a. If we made a new file dir/sub/dir/a, that would not be ignored: dir/a means the same as /dir/a.

One might expect only a leading slash to do this, but in fact, it's any slash, except at the end, that does this. The except at the end part means that if you list sub/ in your top level .gitignore, Git will ignore both files inside dir/sub, because the slash is removed from the end before applying the "contains a slash" rule, then put back on the end for the "matches a directory" rule.

The result is that if you mean to ignore Assets/Plugins/Editor/JetBrains* at any level—not just the current level (wherever this particular .gitignore file lives within your work-tree)—you need the **/ prefix.

Note that you can have a .gitignore file at each level, so you could just find directories named Editor, and if they are in an Assets/Plugins/ containing directory, create a .gitignore here that lists JetBrains*. That would have the same effect as writing **/Assets/Plugins/Editor/JetBrains* at the top level.


1Ignore is really the wrong verb. A file won't be ignored if it's already tracked; listing a file in .gitignore means don't complain about this file if it's untracked, and don't automatically add it with an en-masse "add all files" command. It also gives Git permission to clobber the file in certain cases. But calling the file .git-dont-complain-about-untracked-and-dont-auto-add-and-sometimes-feel-free-to-clobber-these-files would be unweidly, so we say "ignore"...

2
  • Honestly, I think this is a bug. It should be fixed. Thanks for the detailed answer. Dec 9, 2018 at 23:44
  • It probably would make more sense to root/anchor the glob if and only if it starts with / rather than if it contains /. The range of names you can express would remain exactly the same. Whether you can convince the Git folks of this is a separate question entirely, though.
    – torek
    Dec 10, 2018 at 4:29
1

**/Assets/Plugins/Editor/JetBrains*
Will ignore the path doesn't matter what is the root folder of the Assets which mean it can be nested.

Assets/Plugins/Editor/JetBrains*
Will ignore the path statring from the current folder

**/ means that it can be "nested" inside any folder under the location of the current path

1
  • The gitignore is in the root folder of the repository Dec 9, 2018 at 19:18

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.