Untrack并停止在git中跟踪文件 [英] Untrack and stop tracking files in git

查看:460
本文介绍了Untrack并停止在git中跟踪文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 objects 的深度子文件夹,名为 *。object ,我不想跟踪git(Windows)。

I have a deep subfolder called objects with files called *.object which I don't want tracked by git (Windows).

在.gitignore中,我尝试了各种组合(例如 ** / objects / * ** / objects / * 等)无效:每当我做 git status 我看到:

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:

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       foo/src/objects/a.object
#       foo/src/objects/b.object

只有当我将 *。object 添加到.gitignore时,文件才会从未跟踪的文件列表中消失。我的通配符有什么问题?

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?

另外,何时需要 git update-index ,我应该在什么时候执行 git rm --cached myfile

Also, when is git update-index required and when should I do git rm --cached myfile?

是否存在rm的通配符功能,如 git rm --cached ** / foo / *。zip

Is there a wildcard feature for rm like git rm --cached **/foo/*.zip?

UPDATE:同样,添加 .gitignore .gitignore (并不总是可取的,但仍然)没有效果。这是不是很奇怪,因为这些文件可能在过去被跟踪过?

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?

推荐答案

好的,虽然通配符不起作用显然)似乎可以删除整个文件夹:

OK, though wildcards don't work (in Windows apparently) it seems one can remove a whole folder with:

git rm -r --cached "path/to/foo/"

我明白 - 只缓存未缓存 - 您必须 git commit 将其从回购中移除。

I understand that --cached only unstages - you have to git commit to remove them from the repo.

这篇关于Untrack并停止在git中跟踪文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆