Hg (Mercurial): any way to "set aside" the working copy for later?
Asked Answered
T

5

8

Scenario: After your last commit, you decided to do some extensive refactoring of the codebase. After a time, you realize it is taking longer than expected, and you'd really rather put off the refactoring for another time, and work on more pressing tasks. But you don't want to lose all of the refactoring work you've done so far.

So, is there a way to "archive" or "branch" the working copy (essentially, set it aside but keep it in the repository for later access), and then revert to the last good commit and resume from there, without fear of creating multiple heads or getting the two mixed up?

Tsushima answered 27/5, 2011 at 22:53 Comment(1)
How about cloning the repository and working from that?Justificatory
R
18

Don't worry about "the fear of two heads". Two heads is a very normal state. It's called anonymous branches, and it's one of the ways people do temporary branches in Mercurial.

Just commit, and then update to tip-1 and you're ready to go:

hg commit -m "working on XXX"
hg update -r "tip-1"

and away you go. If you want to drop a bookmark (less permanent than a tag) on that head you can, but there's no need to worry about it.

You can always push one head without pushing another using hg push -r HEAD where that can even be hg push -r .

Don't fear heads -- they're what makes a DAG based VCS powerful.

Rideout answered 28/5, 2011 at 3:20 Comment(1)
I just cannot find the +5 button, you'll have to settle for a +1 I'm afraid.Hueyhuff
U
1

You can do this with the mq, attic or shelve extensions.

Uela answered 27/5, 2011 at 23:0 Comment(0)
S
1
  1. Assign a tag to your refactor revision
  2. Commit the tag
  3. Clone the repository again
  4. Revert to the stable version
  5. Work from the stable version
  6. Don't worry about multiple heads, you can easily merge later

Since mercurial uses hard links, you can keep both repositories on your local machine with minimal space used. commands:

$hg tag Refactor
$cd ..
$hg clone Refactor Stable
$cd Stable
$hg revert -r REVISION_NUMBER

extra help:
http://hgbook.red-bean.com/
http://kiln.stackexchange.com/

Skeptic answered 27/5, 2011 at 23:28 Comment(2)
Would I get the same result without the clone? If I tag the working set, commit it, then update to a previous revision, would that end up the same as the Stable repo you mention, with the Refactor changes still available by tag?Tsushima
Yes, that would work as well. The idea of the clone is if you want to quickly go back and forth between the two. The ChangeSets will take care of the merging in both cases.Skeptic
T
1

You can do it the simple way:

$ hg diff -g > tmp
$ hg revert --all

Your changes will now be stored in tmp. You can restore them with

$ hg patch --no-commit tmp

and you'll be back where you were. There are extensions like shelve that automates the above for you.

Tumble answered 14/12, 2011 at 10:39 Comment(0)
A
0

In git you would do a 'stash'. According to This hg has 'shelve', but it requires an extension.

Ause answered 27/5, 2011 at 23:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.