git 如何撤消git中的最后一次提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37420642/
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
How to undo the last commit in git
提问by chintan s
By mistake, I did git add .
and git commit
in the develop
branch. But luckily, I did not do git push
.
错误地,我做到了git add .
并且git commit
在develop
分行。但幸运的是,我没有这样做git push
。
So I wanted to revert it back to original state.
所以我想把它恢复到原来的状态。
I tried git reset --soft
and git reset HEAD --hard
but looks like I have messed it up.
我试过了git reset --soft
,git reset HEAD --hard
但看起来我把它搞砸了。
How do I fix this? I want to go back to original state and possibly keep the code changes.
我该如何解决?我想回到原始状态并可能保留代码更改。
回答by guessimtoolate
I think you haven't messed up yet. Try:
我想你还没有搞砸。尝试:
git reset HEAD^
This will bring the dir to state before you've made the commit, HEAD^
means the parent of the current commit (the one you don't want anymore), while keeping changes from it (unstaged).
这将使目录在您进行提交之前处于状态,这HEAD^
意味着当前提交的父项(您不再需要的那个),同时保留对其的更改(未暂存)。
回答by Always Sunny
Try simply to reset last commit
尝试简单地重置上次提交
git reset --soft HEAD~1