MEM
MEM

Reputation: 31347

What is the difference between /* and / and the very end of a path on .gitignore?

On some .gitignore files we may see:

somedirectory/*

or

somedirectory/

Does this means the first will match recursively while the second one, only that directory ?

Upvotes: 2

Views: 137

Answers (2)

Jan Hudec
Jan Hudec

Reputation: 76316

The later matches the directory, but ignoring directory means ignoring all its contents. So it is recursive.

For the former, the * will only match immediate entries. But since it will match directories as well, and ignoring a directory means ignoring all its contents, it's also recursive.

Git does not track directories; a directory whose all content is ignored is as good as ignored.

Therefore there is no practical difference.

Upvotes: 4

lisachenko
lisachenko

Reputation: 6092

They both will match recursively. But you shouldn't use somedirectory/* pattern because it won't match the somedirectory/ itself. So if you have a cache folder cache/ and ignore pattern cache/*, then git clean -fd will remove cache/ directory with all files in it.

Be careful with patterns for IDEs :) Ignore pattern .idea/* can lead to clear all the settings of the project.

Upvotes: 4

Related Questions