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
447 views
in Technique[技术] by (71.8m points)

git - 如何从临时区域中删除单个文件(撤消git add)?(How do I remove a single file from the staging area (undo git add)?)

Situation: I have a Git repository with files already in the index.

(情况:我有一个Git存储库,其中的文件已经在索引中。)

I make changes to several files, open Git and add these files to my staging area with "git add ."

(我对几个文件进行了更改,打开Git并使用“ git add”将这些文件添加到我的暂存区中。)

Question: How do I remove one of those files from the staging area but not remove it from the index or undo the changes to the file itself?

(问题:如何从登台区域中删除这些文件之一,而不从索引中删除它或撤消对文件本身的更改?)

  ask by PHLAK translate from so

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

1 Reply

0 votes
by (71.8m points)

If I understand the question correctly, you simply want to "undo" the git add that was done for that file.

(如果我正确理解了这个问题,则只想“撤消”对该文件执行的git add 。)

If you need to remove a single file from the staging area, use

(如果您需要从暂存区中删除单个文件 ,请使用)

git reset HEAD -- <file>

If you need to remove a whole directory (folder) from the staging area, use

(如果您需要从暂存区中删除整个目录(文件夹) ,请使用)

git reset HEAD -- <directoryName>

Your modifications will be kept.

(您的修改将被保留。)

When you run git status the file will once again show up as modified but not yet staged.

(当您运行git status ,文件将再次显示为已修改但尚未暂存。)

See the git reset man page for details.

(有关详细信息,请参见git reset手册页 。)


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

...