在 git 中取消跟踪并停止跟踪文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15027873/
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
Untrack and stop tracking files in git
提问by Marc
I have a deep subfolder called objects
with files called *.object
which I don't want tracked by git (Windows).
我有一个深层子文件夹objects
,*.object
其中包含我不想被 git (Windows) 跟踪的文件。
In .gitignore I have tried various combinations (e.g. **/objects/*
or **/objects/*
etc.) to no avail: each time, when I do git status
I see:
在 .gitignore 中,我尝试了各种组合(例如**/objects/*
或**/objects/*
等)但无济于事:每次,当git status
我看到:
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# foo/src/objects/a.object
# foo/src/objects/b.object
It is only when I add *.object
to .gitignore that the files disappear from the untracked files list. What's wrong with my wild cards?
只有当我添加*.object
到 .gitignore 时,文件才会从未跟踪文件列表中消失。我的外卡怎么了?
Also, when is git update-index
required and when should I do git rm --cached myfile
?
另外,什么时候git update-index
需要,什么时候应该做git rm --cached myfile
?
Is there a wildcard feature for rm like git rm --cached **/foo/*.zip
?
rm 有通配符功能git rm --cached **/foo/*.zip
吗?
UPDATE: Similarly, adding the line .gitignore
to .gitignore
(not always desirable but still) has no effect. Is this weirdness because the files may have been tracked in the past?
更新:同样,将行添加.gitignore
到.gitignore
(并不总是可取但仍然)没有效果。这很奇怪,因为文件可能在过去被跟踪过吗?
回答by Marc
OK, though wildcards don't work (in Windows apparently) it seems one can remove a whole folder with:
好的,虽然通配符不起作用(显然在 Windows 中),但似乎可以删除整个文件夹:
git rm -r --cached "path/to/foo/"
I understand that --cached only unstages - you have to git commit
to remove them from the repo.
我知道 --cached 只是 unstages - 你必须git commit
从 repo 中删除它们。