Mercurial: How can a I make a snapshot of my working directory without doing a changeset?

354 views Asked by At

While working on a new feature I arrive at a point where it roughly works, but is still not at a point where I want to create a changeset. I would however create a "restore point" or a "snapsnot" so I can come back to this roughly working version of my codebase. In TFS I would create a shelve set.

In mercurial, shelve sets behave different: As soon as I move a file into a shelf, the file reverts to the state of the last changeset. So for my purpose of creating a snapshot and continue working, this behavior makes shelving not a solution.

How can I snapshot my work and continue with the files as they are?

I know there are many questions about shelving in mercurial here, but I could not find an answer to this question in them.

Comment on the helpful answers by @Mathiasdm and @Gill Bates

For now I go with commit --amend, which is also available in TortoisHG: the commit button can be converted to an amend button.

Ammend adds the changes to the previous commit instead of creating a new changeset. So

  • first I create a commit with the rough version and then
  • improve on it by ammending it.

"hg shelve && hg unshelve --keep" and the mq extension are nice alternatives.

2

There are 2 answers

0
Mathiasdm On BEST ANSWER

One command that is particularly suited for this is:

hg commit --amend

It allows you to create a commit and keep improving it (amending it). Every time you do 'hg commit --amend', all additional changes in the working directory are added to it.

I know this does not sound 'shelve-like', but it sounds like what you need is actually not really a shelve.

0
Gill Bates On

There are many ways to achieve the goal:

Shelve

You can use this command:

hg shelve && hg unshelve --keep

It will create a shelve, then unshelve it to the workspace keeping the shelve in shelve storage.

MQ extension

There is also MQ extension which lets you manage commits as patches. You can create a snapshot with:

hg qnew my_snapshot_name

Then you will be able to refresh it, unapply, reapply, change order, convert to regular changeset and do other useful stuff, check the link for the info.

Patch

You can save just a patch:

hg diff > tmp.diff

And then apply it with:

hg import tmp.diff

Or with:

patch -p1 < tmp.diff

Or you can import in MQ:

hg qimport tmp.diff

Feature branch

You can adjust your VCS workflow and use so called "feature branches" to store feature-specific progress in it and not pollute a main branch with it:

hg branch feature/my_stufff
... work work work ...
hg commit -m 'some progress'
... polish debug finalize ...
hg commit -m 'now it really works'

Then you need to propagate your changes to the main branch. You can do that with rebase extension if you like to keep your history linear:

hg rebase -s feature/my_stuff -d default --collapse

It will take the whole feature branch, put in on top of default branch and collapse all the change sets of feature-branch into one changeset. Of course you can rebase without collapsing.

Or you can just merge your feature-branch to default branch:

hg update default && hg merge feature/my_stuff

This will keep non-linearity.