问题描述
错误的是,我在开发中添加了 git add。和 git commit / code>分支。但幸运的是,我没有做 git push 。
所以我想把它恢复到原始状态。 / p>我试过 git reset --soft 和 git reset HEAD --hard 但看起来像我搞砸了。
我该如何解决这个问题?我想回到原始状态,并可能保持代码更改。
我认为你还没有搞砸。试试:
git reset HEAD ^
在提交之前,这会使目录处于状态, HEAD ^ 表示当前提交的父目录不要再想了),同时保持它的变化(未冻结)。
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.
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).
这篇关于如何撤消git中的最后一个提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!