Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

git - 忽略已经提交到Git存储库的文件[重复](Ignore files that have already been committed to a Git repository [duplicate])

I have an already initialized Git repository that I added a .gitignore file to.

(我有一个已经初始化的Git存储库,向其中添加了一个.gitignore文件。)

How can I refresh the file index so the files I want ignored get ignored?

(如何刷新文件索引,以便忽略要忽略的文件?)

  ask by trobrock translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To untrack a single file that has already been added/initialized to your repository, ie , stop tracking the file but not delete it from your system use: git rm --cached filename

(要取消跟踪已添加/初始化到存储库中的单个文件, 停止跟踪文件但不将其从系统中删除,请使用: git rm --cached filename)

To untrack every file that is now in your .gitignore :

(取消跟踪.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"

To undo git rm --cached filename , use git add filename .

(要撤消git rm --cached filename ,请使用git add filename 。)

Make sure to commit all your important changes before running git add .

(确保在运行git add .之前提交所有重要更改git add .)

Otherwise, you will lose any changes to other files.

(否则,您将丢失对其他文件的任何更改。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...