在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:34:26  来源:igfitidea点击:

Untrack and stop tracking files in git

git

提问by Marc

I have a deep subfolder called objectswith files called *.objectwhich 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 statusI 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 *.objectto .gitignore that the files disappear from the untracked files list. What's wrong with my wild cards?

只有当我添加*.object到 .gitignore 时,文件才会从未跟踪文件列表中消失。我的外卡怎么了?

Also, when is git update-indexrequired 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 .gitignoreto .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 committo remove them from the repo.

我知道 --cached 只是 unstages - 你必须git commit从 repo 中删除它们。