简体   繁体   中英

How to gitignore files in a directory but not files in its sub-directories?

Folder structure

  • foo
    • bar
      • file1.js
      • file2.js
      • baz
        • file3.js
        • file4.js

I would like to gitignore the files directly inside the "bar" directory (file1 and file2), but not the files inside any sub-directory of "bar" (in this example, file3 and file4 should not be ignored).

I checked the docs . Seems to be incomplete.

You can ignore the files in the bar directory

# foo/bar/.gitignore
*.js

and then whitelist in the baz directory

# foo/bar/baz/.gitignore
!*

From the docs on kernel.org :

Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM