开发者

git - ignore files based on mode

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 开发者_如何学Gofile...


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.


It's really going to be best for you to manually maintain the gitignore, probably. You could do this:

*
!*.*

to exclude everything, then include everything with a ".", but I suspect your directories don't have extensions. Currently tracked directories would still be tracked, of course, but if you added a new one, git-status wouldn't see it, and you'd have to use add -f to get it in.

It's probably not good to assume all extension-less files shouldn't be tracked, anyway. You may end up with some naturally - for example, README and INSTALL are pretty common. It's way worse to accidentally ignore a file than to have to modify the gitignore, too. Modifying the gitignore might take a few seconds, but it'll be obvious when you need to do it. If you accidentally ignore a file, you could easily not check it in and lose the work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜