Search code examples
gitvisual-studiogitignore

Why don't the build result directories start ** in VS .gitignore


There's a standard Visual Studio .gitignore file available here.

It includes this section:

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/

Why don't those lines start with the gitignore pattern format **/ so that the search includes all subdirectories?


Solution

  • Relative paths (as your directory names) already are ignored everywhere.

    If you create a structure

    foo/
      bar/x.txt
    bar/x.txt
    

    (where x.txt is just fluff to have non-empty directories)

    and have a .gitignore file containing just

    bar
    

    then git is ignoring both bar directories.

    Absolute paths like /bar would only ignore a top-level directory instead. Are you sure that you're seeing a different behavior?

    The documentation you linked to contains this:

    Two consecutive asterisks ("**") in patterns matched against full pathname may have special meaning:

    A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

    (emphasis mine)