You can undo git add
before commit with
(您可以在提交之前撤消git add
)
git reset <file>
which will remove it from the current index (the "about to be committed" list) without changing anything else.
(这会将其从当前索引(“即将提交”列表)中删除,而无需进行其他任何更改。)
You can use
(您可以使用)
git reset
without any file name to unstage all due changes.
(没有任何文件名可以取消所有应有的更改。)
This can come in handy when there are too many files to be listed one by one in a reasonable amount of time. (当在合理的时间内有太多文件不能一一列出时,这可能会派上用场。)
In old versions of Git, the above commands are equivalent to git reset HEAD <file>
and git reset HEAD
respectively, and will fail if HEAD
is undefined (because you haven't yet made any commits in your repository) or ambiguous (because you created a branch called HEAD
, which is a stupid thing that you shouldn't do).
(在旧版本的Git中,上述命令分别等效于git reset HEAD <file>
和git reset HEAD
,并且如果HEAD
未定义(因为尚未在存储库中进行任何提交)或模棱两可(因为创建了一个名为HEAD
的分支,这是愚蠢的事情,您不应该这样做)。)
This was changed in Git 1.8.2 , though, so in modern versions of Git you can use the commands above even prior to making your first commit: (但是, 在Git 1.8.2中对此进行了更改 ,因此在现代版本的Git中,甚至可以在进行首次提交之前使用上述命令:)
"git reset" (without options or parameters) used to error out when you do not have any commits in your history, but it now gives you an empty index (to match non-existent commit you are not even on).
(当您的历史记录中没有任何提交时,“ git reset”(没有选项或参数)会出错,但是现在它为您提供了一个空索引(以匹配您甚至没有参与的不存在的提交)。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…