How to undo the last commit in git [duplicate]

╄→гoц情女王★ 提交于 2019-12-03 00:04:35

问题


By mistake, I did git add . and git commit in the develop branch. But luckily, I did not do 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.

How do I fix this? I want to go back to original state and possibly keep the code changes.


回答1:


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).




回答2:


Try simply to reset last commit

git reset --soft HEAD~1


来源:https://stackoverflow.com/questions/37420642/how-to-undo-the-last-commit-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!