移动(或“撤消”)最后一次 git commit 到 unstaged 区域
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10846875/
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
Move (or "Undo") last git commit to unstaged area
提问by jlb
What's the best way to move your last git commit back into the "Changes not staged" + "Untracked files" areas (with the commit in question being not-pushed / only in your local repo, effectively removing it from HEAD)?
将上次 git 提交移回“未暂存的更改”+“未跟踪的文件”区域的最佳方法是什么(有问题的提交未被推送/仅在您的本地存储库中,有效地将其从 HEAD 中删除)?
In other words, how do you roll back a commit, but automatically apply that diff to your unstaged area?
换句话说,您如何回滚提交,但自动将该差异应用到您的未暂存区域?
回答by Stefan
You can use git reset
to set the current branch to the preceding commit, i.e. HEAD^
您可以使用git reset
将当前分支设置为前一个提交,即HEAD^
git reset HEAD^
Adding --soft
will keep those files in the index: (ready to be committed)
添加--soft
会将这些文件保留在索引中:(准备提交)
git reset --soft HEAD^
--soft
(…) This leaves all your changed files "Changes to be committed", as git status would put it.
--soft
(...) 这会留下所有更改的文件“要提交的更改”,正如 git status 所说的那样。
回答by John
git-extrasprovides a git undo
command which is an easier to remember way of doing the same thing (along with a number of other handy extras, as the name implies).
git-extras提供了git undo
一个更容易记住的命令来做同样的事情(以及许多其他方便的附加功能,顾名思义)。