25

I'm working on a live server. I've updated to tip and it's caused problems: I need to revert back to a particular changeset (388) where things were OK.

I have no changes of any value on the server, the local changeset does not matter at all. In fact I actually want to kill any local accidental changes or merges so as not to confuse things.

How do I revert to a particular changeset and kill any local changes? Is it something to do with:

hg revert 

---- UPDATE ---

To clarify, what I would like to do is first revert everything locally to changeset 388, and then ensure that my local repo is in such a state that when I do

hg status

I get no output. Otherwise I have a nasty feeling that when I next pull the tip, there will be conflicts to deal with - which I want to avoid, because the local changes are of no value.

---- UPDATE ---

For anyone else in this situation, what eventually fixed it for me was:

rm -rf <repo_dir>
hg clone http://repository
hg update -r 388

That will kill all your local changes, so proceed with caution (but that's what I wanted in this case).

AP257
  • 89,519
  • 86
  • 202
  • 261
  • Just a tip: check out `hg help revert` for documentation about revert. This also works with other commands (`hg help [command name here]`). – derekerdmann Aug 11 '10 at 14:22

3 Answers3

21

Just use the command below, to get to a revision.

hg revert -r REV

It's conflicting with --all.

To kill all local changes, --all should work.

hg revert --all

Don't use rollback. It's a irreversible procedure, so should be used with care.

EDIT

You can update with --clean option. That will discard any uncommitted change. And then update to some changeset.

simplyharsh
  • 35,488
  • 12
  • 65
  • 73
  • hg revert --all -r 388 worked - thank you! However, hg status still shows a bunch of differences between the local repository and the remote one, due to all the faffing and panicking I did. Is there any way to delete all the local changesets? – AP257 Aug 11 '10 at 14:05
  • You can't delete local changesets. I'd clone the repo from the server and then hg update 388 to your desired revision. – Valentin V Aug 11 '10 at 14:14
  • 1
    @AP257: you don't need to **revert**. You need to **update** as @jk answered – zerkms Aug 11 '10 at 14:15
  • delete the local repo and just re-clone from the server? depends what you want to be in the history as well as the working copy – jk. Aug 11 '10 at 14:16
  • Are there some untracked files ?? – simplyharsh Aug 11 '10 at 14:16
15
server:
- ..
- rev 386
- rev 387
- rev 388
- rev 389

clone to production

-- testing stuff, it doesn't work!
-- panic!
-- rev 390 (in panic)
-- rev 391 (in panic)
-- cool down, thinking, need to go back to 388
-- one way: hg update -C -rev 388 (to keep 390, 391)
-- other way: rm -rf dir (to discard 390, 391)
-- hg clone http://server/hg
-- cd dir
-- hg update 388 
-- testing, now works

There is also a wonderful Purge extension. Very solid stuff, it deletes all untracked files from working directory.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Valentin V
  • 24,971
  • 33
  • 103
  • 152
  • Ah - so to achieve the state that I describe in the update above, I either need to delete all local files, or I need to use the Purge extension? makes sense... – AP257 Aug 11 '10 at 17:12
  • Fixed this using rm -rf dir and hg clone / hg update 388, as you suggested. I thought it was clear that I wanted to discard everything, but apparently not from the other comments..! Thanks for your help! – AP257 Aug 15 '10 at 21:49
6

I don't think it is really clear what you want but my interpretation would be hg update -C -rev 388 but you could equally well be after revert, or possibly (unlikely) even rollback. my answer to this question gives a good difference between update and revert

you really need to work out what you want to see in the working copy AND what you want the state of the history to be like to choose between them

Community
  • 1
  • 1
jk.
  • 13,817
  • 5
  • 37
  • 50
  • since it wasn't clear: I wanted the working copy to be update 388, and the history to be completely empty. – AP257 Aug 15 '10 at 21:50
  • 2
    History and status are two different things. You can be on rev 388, with rev 389 and 390 in the history, but with no local changes so status is empty. – Lasse V. Karlsen Aug 15 '10 at 21:56