Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - ignore files based on mode

Tags:

git

I want to ignore executable files that do not have an extension

For example:

gcc -o foo foo.c

I know I could add 'foo' to my .gitignore file, but if I decide to change the name of the executable I would need to update my .gitignore file...

like image 402
danjarvis Avatar asked Oct 21 '09 21:10

danjarvis


1 Answers

I usually handle this using makefile hacks. In my Makefile i have the name of the executable $(name) and then I do this:

#first rule
all: gitignoreadd ... more depends
    ... some commands ...

gitignoreadd:
    grep -v "$(name)" .gitignore > temp
    echo $(name) >> temp
    mv temp .gitignore

gitignoreremove:
    grep -v "$(name)" .gitignore > temp
    mv temp .gitignore

That rule can then just be a dependency of the make somewhere appropriate. Then you usually have a 'make clean' rule as follows:

clean: gitignoreremove
   rm *.o *.othergarbagefiles $(name)

This should do the trick. It's a hack but it works for me. The only thing is that you must run make clean before changing the name to automatically clean everything up.

like image 191
Robert Massaioli Avatar answered Sep 28 '22 18:09

Robert Massaioli