Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 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 Reply

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...