Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all local changesets and revert to tree

I'm using Mercurial and I've got into a terrible mess locally, with three heads. I can't push, and I just want to delete all my local changes and commits and start again with totally clean code and a clean history.

In other words, I want to end up with (a) exactly the same code locally as exists in the tip of the remote branch and (b) no history of any local commits.

I know hg update -C overwrites any local changes. But how do I delete any local commits?

To be clear, I have no interest in preserving any of the work I've done locally. I just want the simplest way to revert back to a totally clean local checkout.

like image 575
Richard Avatar asked Jan 26 '10 11:01

Richard


People also ask

How do you Uncommit in Heartgold?

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.


1 Answers

When the simplest way (a new hg clone) isn't practical, I use hg strip:

% hg outgoing -l 1 % hg strip $rev # replace $rev with the revision number from outgoing 

Repeat until hg outgoing stays quiet. Note that hg strip $rev obliterates $rev and all its descendants.

Note that you may have to first enable strip in your Mercurial settings.

PS: an even smarter approach is to use the revset language, and do:

% hg strip 'roots(outgoing())' 
like image 189
just somebody Avatar answered Sep 28 '22 22:09

just somebody