开发者

git equivalent for hg rollback

How would I "rollback" the last commi开发者_高级运维t in git without deleting any changes?

This is something I've done often in hg:

  • Commit "Fixed 107."
  • Remembered that I forgot to do something
  • hg rollback
  • Do something
  • Commit "Fixed 107."


Try this:

git reset --soft HEAD^

I found it to be the same of 'hg rollback', because:

  • last commit cancelled
  • changes preserved
  • files previously committed are staged

You can also create a rollback git alias like this:

git config --global alias.rollback 'reset --soft HEAD^'

So, you can now just type git rollback to have exactly the same command that you have on Mercurial.


With git you may actually prefer to use the --amend option in that case.

  • Commit "Fixed 107."
  • Remembered that I forgot to do something
  • Do something
  • git commit --amend and edit the notes

If you need to rollback for other reasons take a look at git revert


In this specific instance I would git commit --amend. If you haven't pushed yet and you've already committed other changes then you can also use git rebase -i to edit whichever commit you want.


I was trying to do an hg rollback in my git repository and I managed using

git reset HEAD~

this left me with my changes in the working directory but now unstaged. Source

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜