Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial:Remove last commit

Tags:

mercurial

I was working in default, but thought to be working in another branch. I commited, but didn't push.

Now I want to change branches and commit the changes to another branch, but also dont want the commit to go to default.

How do I undo that commit?

like image 849
Euphe Avatar asked Apr 17 '14 14:04

Euphe


People also ask

How can I delete last commit in Mercurial?

If you are still in the draft phase (not pushed elsewhere yet), use the built-in extension hg strip <rev> command. Otherwise, you should do a hg backout , which will reverse the changeset. In case you still need the commit you made, I suggest you export it to import it again in the correct branch, before stripping.

How do you Uncommit in mercurial?

A simple way to 'uncommit' your last commit is to use hg strip -r -1 -k. In case the link breaks, the documentation mentioned by @phb states: hg rollback Roll back the last transaction (DANGEROUS) (DEPRECATED) Please use 'hg commit --amend' instead of rollback to correct mistakes in the last commit.

How do you revert push changes in mercurial?

You need to login to the server and use the hg strip command. If you cannot login to the server, you are out of luck; you can hg backout then push again, but this will leave the bad commits on the server along with the commit that undoes them. Show activity on this post. hg revert -r .

How do I revert a commit in TortoiseHg?

In the TortoiseHg client's Commit dialog, right-click the needed file and then click Revert.


2 Answers

If you are still in the draft phase (not pushed elsewhere yet), use the built-in extension hg strip <rev> command. Otherwise, you should do a hg backout, which will reverse the changeset.

In case you still need the commit you made, I suggest you export it to import it again in the correct branch, before stripping.

like image 168
Vince Avatar answered Oct 18 '22 22:10

Vince


If "another branch" already exist, you must move changeset to it, using hg rebase (rebase extension have to be enabled)

like image 20
Lazy Badger Avatar answered Oct 19 '22 00:10

Lazy Badger