RNA
RNA

Reputation: 153251

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?

Upvotes: 1

Views: 972

Answers (1)

Andy
Andy

Reputation: 46324

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.

Upvotes: 4

Related Questions