简体   繁体   中英

how to track certain files in subdirectories but not all the other files with git?

I'd like to track files in this style

# Ignore everything
*
# But not these files...
!.gitignore
!/projectA/Makefile
!/projectB/Makefile

It turns out git can't track the Makefiles in the subdirectories of projectA and projectB . One solution is to create .gitignore file in the subdirectories, but I don't like it because I have to manually create a lot of different .gitignore files. Any idea how to do that in the .gitignore of git root dir?

You can do something like this:

  1. You need to track the folder in order to track the Makefile in the folder
  2. But we don't want to track anything in the folder
  3. Except the Makefile .

Put these pieces together to get these three lines in your .gitignore

!/projectA/
/projectA/*
!/projectA/Makefile

It's a bit verbose, but I don't know of a shorter method.

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