tags:

views:

96

answers:

5

Suppose that:

  • I have a repo called MyRepo.
  • I have uncommitted changes in my working directory.
  • I do a pull from Repo1 and that creates a branch in MyRepo
  • I want to do a merge of what I already had in my repo with what I have just pulled.

As described here, the merge process changes the state of the working directory.

In my scenario, I don't want to loose the uncommitted changes that are in my working directory because at that point, I'm interested in changing the state of MyRepo; not the state of my working directory.

Is there a way to go through the merging process, including resolving conflicts manually, without affecting the content my working directory? Can this process be done in temporary files only? Or should I shelve my changes, do the merge and then unshelve to restore my working dir to the state it was before the merge?

+1  A: 

You could clone your repository to your latest checkin, merge the changes with the clone, commit, and then pull the new changeset from your cloned repository back into your current one.

Nate Heinrich
+2  A: 

You can't do that. As the documentation says, merge really is a working tree operation. Resolving conflicts without testing the result is crazy. Either shelve or commit the changes and then do the merge. If you don't want the commit to be visible anywhere, you can commit the change, update to the previous revision, merge the new branch, apply the temporarily committed patch and strip that temporary branch.

Lukáš Lalinský
+1 to shelving. It sounds like the most straightforward way to proceed to merge without affecting your in-progress changes.
gavinb
A: 

I'm pretty new to mercurial, but couldn't you clone from your local repository and copy your working copy over to the clone? You could then run your merge in the original? You'd preserve the state of your working copy in the clone while being free to allow the change of the original's working copy.

Test this first. I've never done it in hg.

+3  A: 

Use shelve or attic extensions to temporarily stash your changes while you merge.

Marcus Lindblom
A: 

Just do it in a clone.

  1. Clone MyRepo to MyRepo-merger, which will pull over all the committed changes, but not your uncommitted changes
  2. Inside MyRepo-merger do a pull from Repo1.
  3. Inside MyRepo-merger do all the hg merges you want
  4. Inside MyRepo-merger push to either Repo1 or the original MyRepo

Pushing back to MyRepo won't alter the working dir of MyRepo, so that's a safe action.

Remember in Mercurial that clones are incredibly fast and cheap -- on modern file systems they use hardlinks under the covers so they're not even taking up much space on disk.

Ry4an