git 忽略目录 "build"及其所有内容,但不包括 "build.xml"

标签 git ant gitignore

我在一个以 Ant 为构建系统的项目中使用 git。 由于我不想将“构建”目录添加到 git 但需要添加 build.xml 文件,因此我在 .gitignore 中使用了以下两行 文件:

build/
!build.xml

有没有更好/更简洁的方式?

更新: 结果是 build.xml 被忽略了,因为路径上方的目录中有 .gitignore。删除后,build/ 正确地仅忽略构建文件夹,而不是旁边的 build.xml 文件。

最佳答案

不,没有更好的方法,几乎​​就是这样做的方法。准确地说,

build/*
!build/build.xml

因为您想要拥有该文件夹并忽略其中除 build.xml 之外的所有其他文件。

请注意,尽管 Ant 的常见目录布局是 build.xml 位于应用程序根文件夹中,而构建文件夹仅包含构建期间创建的文件。请参阅更多基本原理,例如,here .


编辑。如果您在应用程序根目录中确实有 build.xml,只需

build

in .gitignore 应该足够了。但是,应该注意它只适用于检测新条目,如果你已经向 git 提交了一些东西,你必须自己删除它。

关于git 忽略目录 "build"及其所有内容,但不包括 "build.xml",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13341374/

相关文章:

eclipse - Egit 对 Package Explorer 中括号中的数字意味着什么

git - TeamCity 在一个 Git 存储库上卡在 "Updating sources"

python - 匹配 Ant 路径的正则表达式

git:每个 Remote 都有不同的 .gitignore 文件

windows - 在 Windows 上忽略 Git 存储库中的目录

Git 压缩提交敏感数据

git - 为什么我们在 git 中需要 SSH key ?

java - 在 ant 脚本中运行 UNIX 命令 - build.xml

java - 使用 <foreach> 时的 "failed to create task or type foreach"故障排除

rust - 如何忽略 .gitignore 中的 Rust 可执行文件?