Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 727
Nairou Avatar asked May 27 '11 22:05

Nairou


4 Answers

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.

like image 81
Ry4an Brase Avatar answered Oct 04 '22 10:10

Ry4an Brase


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

like image 27
Neil Avatar answered Oct 04 '22 11:10

Neil


  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/

like image 32
maher.cs Avatar answered Oct 04 '22 09:10

maher.cs


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.

like image 43
Martin Geisler Avatar answered Oct 04 '22 09:10

Martin Geisler