问题描述
我有一个已经初始化的Git仓库,我添加了一个 .gitignore
文件。我怎样才能刷新文件索引,以便我忽略的文件被忽略?
I have an already initialized Git repository that I added a .gitignore
file to. How can I refresh the file index so the files I want ignored get ignored?
推荐答案
em>文件已被添加/初始化到您的存储库, ie ,停止跟踪文件但不会从系统中删除它使用: git rm --cached filename code>
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
为了解每个文件现在位于 .gitignore
:
首先提交所有未完成的代码更改,然后运行以下命令:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
这会从索引(暂存区域)中删除所有已更改的文件,然后只需运行:
This removes any changed files from the index(staging area), then just run:
git add .
提交:
Commit it:
git commit -m ".gitignore is now working"
要撤消 git rm --cached filename
,请使用 git add filename
。
这篇关于忽略已经提交给Git存储库的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!