Un-ignoring a file in an ignored directory in git

心已入冬 提交于 2019-12-21 19:49:21

问题


In my .gititnore I have an entry:

/build

Which works well- the entire directory is ignored by git. Now, I just want to make an exception to this rule and keep this file /build/outputs/mapping/release/mapping.txt in git.

How can I do this?


回答1:


The current rule for gitignore is

It is not possible to re-include a file if a parent directory of that file is excluded.

That means:

  • you need to ignore all the files recursively: that is '**'
  • exclude all the folders recursively: those are '**/'
  • exclude the file you want (which will work because its parent folder is not ignored as well)

Result:

/build/**
!/build/**/
!/build/outputs/mapping/release/mapping.txt

Check what is and is not ignored with git check-ignore -v (the -v is important):

git check-ignore -v -- afile


来源:https://stackoverflow.com/questions/37202089/un-ignoring-a-file-in-an-ignored-directory-in-git

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