Christian
Christian

Reputation: 577

hg: undo checkout of old commit while having local changes

Using mercurial, I regularly run into the following problem which I am not able to securely resolve:

  1. I commit my changes doing hg commit -m "my changes"
  2. I edit some file
  3. I checkout an old commit doing hg checkout -r -15

The problem is that in between (2) and (3), I forgot to first commit my uncommitted changes. mercurial then tries to merge my local changes into the old commit.

How do I undo the checkout in (3) and get back to stage (2)?

This is, I would like to again have the last commit being the commit in (1) and would still like to have the uncommitted local changes in (2).

Upvotes: 0

Views: 243

Answers (1)

Lazy Badger
Lazy Badger

Reputation: 97260

How do I

Short answer

Nohow

Longer answer

You can't restore the exact state of working directory anyway. But you can:

  • block hg up with dirty working directory (with uncommitted changes): redefine update in aliases as hg up -c
  • store WIP in shelve|MQ before update: redefine (again) command as shell-alias with two consecutive commands. Restoring changes still will be you handwork

Upvotes: 1

Related Questions