Git - undo commit (git reset --soft) does nothing

最后都变了- 提交于 2020-02-07 01:58:27

问题


I just did a commit and realized I need to undo the commit without deleting any changes....how would I do that? I have tried git reset --soft and that did nothing, no errors nothing, when I enter that command, literally nothing happens. What am I doing wrong?


回答1:


git reset --soft implies HEAD, but you want to go back to the commit before HEAD, thus :

git reset --soft HEAD^



回答2:


Try this:

git reset --soft HEAD~1

The advantage of this way is you can reset softly for n latest commits, just let the command know expected number of commits to reset softly.

For example, to reset softly last two commits:

git reset --soft HEAD~2

You might also want to learn about various modes of reset.



来源:https://stackoverflow.com/questions/59937046/git-undo-commit-git-reset-soft-does-nothing

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