Reputation: 24364
There are some files we want ignored, not tracked, by git, and we are having trouble figuring out how to do that.
We have some third-party C
library which is unpacked and we have it in Git. But when you configure && make
it, it produces many new files. How to write .gitignore
to track source files and not the new stuff. (it's not like forbidding *.o
)
Edit: There are at least 12 file-types. So we would like NOT to enumerate, which type we want and which not.
Upvotes: 4
Views: 192
Reputation: 11726
Explicitly specifying which files should be tracked and ignoring all others might be a solution. *
says ignore everything and subsequent lines specify files and directories which should not be ignored. Wildcards are allowed.
*
!filename
!*.extension
!directory/
!/file_in_root_directory
!/directory_in_root_directory
Remember that the order matters. Putting *
at the end makes all previous lines ineffective.
Take a look at man gitignore(5) and search for !
. It says
Patterns have the following format:
(...)
An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.
Upvotes: 3
Reputation: 4227
I would make sure the repo is clean (no changes, no untracked files), run configure && make
and then put the newly untracked filed into the ignore file. Something like git status --porcelain | fgrep '??' | cut -c4-
will pull them out automatically, but it would be worth some eyeball time to make sure that is correct...
Upvotes: 0
Reputation: 71400
I'm not sure why you say "it's not like forbidding *.o
", but I think you mean that there aren't any good patterns you can identify that apply to the generated files but not to the source files? If it's just a few things that appear (like individual built executables that often don't have any extension on Linux), you can name them explicitly in .gitignore
, so they aren't a problem.
If there really are lots and lots of files that get generated by the build process that share extensions and other patterns with the source files, then just use patterns that do include your source files. You can even put *
in .gitignore
if it's really that bad. This will mean that no new files show up when you type git status
, or get added when you use git add .
, but it doesn't harm any files that are already added to the repository; git will still tell you about changes to them fine, and pick them up when you use git add .
. It just puts a bit more burden on you to explicitly start tracking files that you do care about.
Upvotes: 0
Reputation: 10103
Use !
to include all the types of files you need. Something like in the following example"
*
!*.c
!*.h
Upvotes: 6