Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git equivalent for hg rollback

Tags:

How would I "rollback" the last commit 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."
like image 510
Nick Zalutskiy Avatar asked Feb 02 '11 23:02

Nick Zalutskiy


People also ask

What is the equivalent of HG?

1 mm of Hg pressure is equivalent to one torr and one torr is equivalent to 133. 3 N/m2.

How do I rollback in git?

The git revert command is used for undoing changes to a repository's commit history. Other 'undo' commands like, git checkout and git reset , move the HEAD and branch ref pointers to a specified commit. Git revert also takes a specified commit, however, git revert does not move ref pointers to this commit.

How do I revert a commit in HG mercurial?

If you want to revert changes already committed: To backout a specific changeset use hg backout -r CHANGESET . This will prompt you directly with a request for the commit message to use in the backout. To revert a file to a specific changeset, use hg revert -r CHANGESET FILENAME .

What does hg rollback do?

The hg backout command lets you “undo” the effects of an entire changeset in an automated fashion. Because Mercurial's history is immutable, this command does not get rid of the changeset you want to undo. Instead, it creates a new changeset that reverses the effect of the to-be-undone changeset.


2 Answers

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.

like image 177
iacopo Avatar answered Oct 11 '22 04:10

iacopo


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

like image 31
chmullig Avatar answered Oct 11 '22 04:10

chmullig