Search code examples
androidgitgitignore

What is the different between /build and build/ in gitignore?


I notice the recommendation for .gitignore for Android in https://stackoverflow.com/a/17803964/3286489 have both /build and build/. What are their differences? Should we have both, or just one will do?


Solution

  • /build is what I like to call an anchored name. It matches the file or directory name build at the level of the tree where the .gitignore resides. So this excludes /build, whether it is a file or directory, but not abc/build, whether that is a file or directory.

    Meanwhile, build/ is not anchored, so it matches at any level of the tree here or below. It does however have a trailing slash, so it only matches directories (or folders if you prefer that word) named build. So if there is an abc/build or def/ghi/build, it is matched if and only if it is a directory.