.gitignore 不适用于 **/*.xyz

.gitignore does not work for **/*.xyz

我的 git 项目包含我不想推送到存储库的 .cas 文件。我因此添加了行

**/*.cas

到我的 .gitignore 文件,但 .cas 文件仍会出现在 git status 中。 在阅读了许多其他帖子后,我检查了 .gitignore 条目是否没有尾随空格,并且它们确实有 unix 行更改说明符。

然后我 运行 按照此处的建议执行以下命令: .gitignore does not work

git rm -r --cached .
git add .

但徒劳无功! git status 仍然报告例如

new file:   calc/2_preliminary/1_CFD/7_Calc_Fluent/03_stationary_vof_stationary/mesh_04/run_10000.cas

有什么想法吗?非常感谢。

更新

.gitignore文件内容:

calc/
0_BSc_Alvarez/
calc/0_Test/
documentation/Tutorial_Fluent/
literature/
thunderbird/
**/.idea/
.zim
**/ND800_*
**/*.cas
**/*.dat
**/*.cdat
**/*.uns
**/*.msh
**/*.bak

git版本为1.7.1

您的说明部分正确。你运行:

git rm -r --cached .

删除了 Git 跟踪的不需要的文件。但出于某种原因,您决定使用

再次将其添加回去
git add .

这导致不需要的文件现在显示为 文件:

new file:   calc/2_preliminary/1_CFD/7_Calc_Fluent/03_stationary_vof_stationary/mesh_04/run_10000.cas

它是新文件的原因是因为您已经告诉 Git 忘记它。

正确的做法应该是只在回购中暂存您真正想要的文件,这会排除以 .cas.

结尾的文件

更新:

尝试 运行ning git rm 但这次只包含 .cas 个文件:

git ls-files | grep '\.cas$' | xargs git rm

现在,如果您 运行 git status 您应该只会看到 .cas 文件被删除。好吧,它们实际上并未从您的本地文件系统中删除,但它们将从存储库中删除。

您在评论中说您使用 git v1.7.1。旧 git 版本 的问题。 **/ 模式仅在 1.8.2 中添加,因此您的 git 无法理解它。此外,你并不真的需要 **/ 部分,你应该只使用

*.cas