我怎样才能让 Git“忘记"?关于被跟踪但现在在 .gitignore 中的文件? [英] How can I make Git "forget" about a file that was tracked, but is now in .gitignore?

查看:18
本文介绍了我怎样才能让 Git“忘记"?关于被跟踪但现在在 .gitignore 中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git 正在跟踪一个文件,但现在该文件在 .gitignore 列表中.

There is a file that was being tracked by Git, but now the file is on the .gitignore list.

但是,该文件在编辑后一直显示在 git status 中.你如何强迫 Git 完全忘记它?

However, that file keeps showing up in git status after it's edited. How do you force Git to completely forget about it?

推荐答案

.gitignore 将阻止将未跟踪的文件(没有 add -f)添加到集合中Git 跟踪的文件,但是 Git 将继续跟踪任何已经被跟踪的文件.

.gitignore will prevent untracked files from being added (without an add -f) to the set of files tracked by Git, however Git will continue to track any files that are already being tracked.

要停止跟踪文件,您需要将其从索引中删除.这可以通过这个命令来实现.

To stop tracking a file you need to remove it from the index. This can be achieved with this command.

git rm --cached <file>

如果要删除整个文件夹,则需要递归删除其中的所有文件.

If you want to remove a whole folder, you need to remove all files in it recursively.

git rm -r --cached <folder>

从主修订中删除文件将在下一次提交时发生.

The removal of the file from the head revision will happen on the next commit.

警告:虽然这不会从您的本地删除物理文件,但会在下一个 git pull 上从其他开发人员的机器上删除文件.

WARNING: While this will not remove the physical file from your local, it will remove the files from other developers machines on next git pull.

这篇关于我怎样才能让 Git“忘记"?关于被跟踪但现在在 .gitignore 中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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