Reputation: 1485
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?
Upvotes: 0
Views: 939
Reputation: 489083
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"...
Upvotes: 7
Reputation: 142362
**/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
Upvotes: 1