Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure git to track only one file extension

I have one directory tree with many kind of different files. There are 300 directories on the parent directory. Each directory could have other sub directories.

I only want to track *.cocci on all sub directories. Here is my .gitignore:

* !*.cocci 

But it do not work, as the files on sub directories are not tracked. How can I tell git that I only want to track *.cocci on all sub directories?

like image 669
Peter Senna Avatar asked Oct 09 '12 12:10

Peter Senna


People also ask

How untrack a file in git?

Removing Files To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don't see it as an untracked file the next time around.

How to check in modified files in git?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed.

How do I ignore a folder in git?

If you want to maintain a folder and not the files inside it, just put a ". gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository.


1 Answers

Read this question.

You want:

# Blacklist everything * # Whitelist all directories !*/ # Whitelist the file you're interested in.  !*.cocci  

Note, this'll track only *.cocci files. Yours doesn't work because you ignore everything (that's the first line), which ignores all subdirectories.

like image 157
simont Avatar answered Oct 17 '22 16:10

simont