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

限于喜欢 提交于 2019-12-12 10:46:24

问题


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:


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




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/2411418/how-to-hg-merge-without-affecting-the-working-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!