如何“合并”不影响工作目录?
假设:
- 我有一个名为 MyRepo 的存储库。
- 我的工作目录中有未提交的更改。
- 我从 Repo1 中进行拉取,并在 MyRepo 中创建一个分支,
- 我想将我的存储库中已有的内容与我刚刚拉取的内容进行合并。
如此处所述,合并过程会更改工作状态目录。
在我的场景中,我不想丢失工作目录中未提交的更改,因为此时我有兴趣更改 MyRepo 的状态;不是我的工作目录的状态。
有没有办法完成合并过程,包括手动解决冲突,而不影响我的工作目录的内容?这个过程只能在临时文件中完成吗?或者我应该搁置我的更改,进行合并,然后取消搁置以将我的工作目录恢复到合并之前的状态?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用搁置或attic 扩展,用于在合并时临时存储您的更改。
Use shelve or attic extensions to temporarily stash your changes while you merge.
您可以将存储库克隆到最新的签入,将更改与克隆合并,提交,然后将新的更改集从克隆的存储库拉回到当前的存储库中。
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.
你不能那样做。正如文档所说,合并确实是一个工作树操作。在不测试结果的情况下解决冲突是疯狂的。搁置或提交更改,然后进行合并。如果您不希望提交在任何地方可见,您可以提交更改、更新到以前的修订版、合并新分支、应用临时提交的补丁并删除该临时分支。
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.
只需在克隆中执行即可。
hg merge
推送回 MyRepo 不会改变 MyRepo 的工作目录,因此这是一个安全的操作。
请记住,在 Mercurial 中,克隆速度非常快且成本低廉——在现代文件系统上,它们在幕后使用硬链接,因此它们甚至不会占用太多磁盘空间。
Just do it in a clone.
hg merge
s you wantPushing 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.
我对 Mercurial 还很陌生,但是您不能从本地存储库克隆并将工作副本复制到克隆吗?然后你可以在原来的版本中运行你的合并吗?您可以在克隆中保留工作副本的状态,同时可以自由地更改原始工作副本。
首先测试一下。我从来没有在hg中做过。
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.