Sylvain
Sylvain

Reputation: 19279

How to 'hg merge' without affecting the working directory?

Suppose that:

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?

Upvotes: 7

Views: 1544

Answers (5)

Macke
Macke

Reputation: 25710

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

Upvotes: 5

Ry4an Brase
Ry4an Brase

Reputation: 78350

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.

Upvotes: 2

Sniggerfardimungus
Sniggerfardimungus

Reputation: 11782

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.

Upvotes: 0

Lukáš Lalinský
Lukáš Lalinský

Reputation: 41316

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.

Upvotes: 3

Nate Heinrich
Nate Heinrich

Reputation: 1805

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.

Upvotes: 3

Related Questions