Why is .gitignore not including a file prefixed by a !

谁都会走 提交于 2020-01-03 09:38:12

问题


My .gitignore file reads as follows:

build/
glucosia.xcodeproj/
!glucosia.xcodeproj/project.pbxproj
core-plot/framework/build
core-plot/framework/CorePlot-CocoaTouch.xcodeproj/
!core-plot/framework/CorePlot-CocoaTouch.xcodeproj/project.pbxproj
.DS_Store
Classes/.DS_Store

Strangely, glucosia.xcodeproj/project.pbxproj is not ignored, as I would expect.

But, core-plot/framework/CorePlot-CocoaTouch.xcodeproj/project.pbxproj is still being ignored.

Any ideas?

Thanks!


回答1:


As mentioned in the gitignore man page:

A gitignore file specifies intentionally untracked files that git should ignore

If glucosia.xcodeproj/project.pbxproj (as suggested by Alan in the comments) is already tracked, you need to remove it from the cache, and then the gitingore directive will take effect.

git rm --cached glucosia.xcodeproj/project.pbxproj

If the file was already committed, see this SO answer (git commit --amend to remove it from the latest commit)




回答2:


I had the same problem, but a different solution. If you ignore a directory but not a file within it, it will not work. You have to ignore a directory's files.

This doesn't work:

conf/
!conf/config.json.orig

This will work:

conf/*
!conf/config.json.orig


来源:https://stackoverflow.com/questions/2196982/why-is-gitignore-not-including-a-file-prefixed-by-a

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