Configure git to track only one file extension

血红的双手。 提交于 2019-12-02 17:12:44
simont

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.

To extend @simont answer, if we wanted to whitelist *.cocci files of a given directory and its subdirectories I would wrongly have entered:

directory/*
!directory/*/
!directory/*.cocci 

That seems not to be including *.cocci files under directory/subtree.

In order to find all *.cocci files in all sub-directories of directory entered the following:

directory/**
!directory/*/
!directory/**/*.cocci 

It is impossible to unignore directory by !dir in .gitignore, but then it is still possible to add directory by hand:

git add dir -f

So if the .gitignore file looks like:

*
!*.txt

Then when you do git add . new *.txt files are then added. New directory will not be auto-added, it have to be added by hand by git add dir -f

Have you tried !*/*.cocci instead of your !*.cocci?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!