git 忽略目录“build”及其所有内容,但不忽略“build.xml”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13341374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git ignore directories "build" and all their contents but not "build.xml"
提问by Marcus Junius Brutus
I am using gitin a project where Antis the build system. Since I do not wish to add "build" directories to gitbut need to add build.xmlfiles I have resorted to the following two lines in my .gitignorefiles:
我在Ant是构建系统的项目中使用git。由于我不想向git添加“build”目录但需要添加build.xml文件,因此我在.gitignore文件中使用了以下两行:
build/
!build.xml
Is there a better / more concise way ?
有没有更好/更简洁的方法?
UPDATE:turns out build.xmlwas ignored due to a .gitignorein a directory higher up the path. Once that was removed, build/correctly ignores only the build folder, not the build.xmlfile beside it.
更新:结果是build.xml被忽略,因为在路径上方的目录中存在.gitignore。一旦删除,build/正确地仅忽略 build 文件夹,而不是它旁边的build.xml文件。
回答by eis
No, there is no better way, that's pretty much the way to do it. To be precise,
不,没有更好的方法,这几乎就是这样做的方法。准确地说,
build/*
!build/build.xml
As you want to have the folder and ignore all other files in it except build.xml.
因为您想要拥有该文件夹并忽略其中除 build.xml 之外的所有其他文件。
Note though that common directory layout for Ant is that build.xml is in the app root folder, whereas build folder only contains files created during build. See further rationale in, for example, here.
请注意,Ant 的常见目录布局是 build.xml 位于应用程序根文件夹中,而 build 文件夹仅包含在构建期间创建的文件。例如,请参阅此处的进一步理由。
Edit. if you actually have build.xml in the app root, just
编辑。如果您确实在应用程序根目录中有 build.xml,只需
build
in .gitignore should be enough.
在 .gitignore 应该足够了。
回答by Nick
You can also just ignore /build/, that will ignore only the folder called build, no files.
您也可以忽略 /build/,它只会忽略名为 build 的文件夹,不忽略文件。