忽略已经提交给Git存储库的文件 [英] Ignore files that have already been committed to a Git repository

查看:61
本文介绍了忽略已经提交给Git存储库的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经初始化的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存储库的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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