git 如何从暂存区中删除目录子树?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5359830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:24:48  来源:igfitidea点击:

How do I remove a directory subtree from the staging area?

gitgitignoregit-add

提问by Acorn

I made a new repository, and ran git add -A. I then noticed that there was a folder containing about 100 files that shouldn't have been included, so I added it to .gitignore.

我创建了一个新的存储库,然后运行git add -A. 然后我注意到有一个文件夹包含大约 100 个不应该包含的文件,所以我将它添加到.gitignore.

How do I now clear the staging area so that I can addall my files again taking into account the updated .gitignore?

我现在如何清除暂存区,以便我可以add再次考虑更新的所有文件.gitignore

回答by Greg Bacon

In #git, you said you unintentionally added a directory that should have been ignored, so run

在#git 中,你说你无意中添加了一个应该被忽略的目录,所以运行

git rm --cached -r directory-name

to recursively remove the tree rooted at directory-namefrom the index.

以递归方式directory-name从索引中删除以 at为根的树。

Don't forget to update .gitignore!

不要忘记更新.gitignore

回答by Matthew Flaschen

You can just use the command:

你可以只使用命令:

git reset

回答by Busilinks

Make sure you remember to put the sin --global core.excludesfile .gitignore.txt

一定要记住把s--global core.excludesfile .gitignore.txt

excludesfilevs excludefile

excludesfile对比 excludefile

Maybe this will save someone else the hour I lost...

也许这会为别人节省我失去的时间......