Mercurial:在一个仓库中合并分支之间的一个文件 [英] Mercurial: Merging one file between branches in one repo

查看:70
本文介绍了Mercurial:在一个仓库中合并分支之间的一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在汞仓库中有两个分支时,如何只将一个文件与另一个分支合并,而不会合并变更集中的所有其他文件?

When I have two branches in Hg repo, how to merge only one file with another branch, without having all other files from changeset merged?

是否可以仅合并某些文件,而不合并整个变更集?

Is it possible to merge only certain files, instead of whole changeset?

推荐答案

警告:@Martin_Geisler建议使用的这种虚拟合并"确实会使您搞砸,如果以后您想对它们进行真正的合并的话两个分支.虚拟合并将被记录,并说您合并到将虚拟合并合并到的分支中-您将看不到更改.或者,如果您合并到另一个分支,则该另一个分支上的更改将被撤消.

WARNING: such a "dummy merge", as is recommended by @Martin_Geisler, can really mess you up, if later you want to do a true merge of the two branches. The dummy merge will be recorded, and say that you merge into the branch you did the dummy merge to -- you will not see the changes. Or if you merge into the other branch, the changes on that other branch will be undone.

如果您只想将整个文件从一个分支复制到另一个分支,则只需执行以下操作:

If all you want is to copy an entire file from one branch to another, you can simply do:

   hg update -r to-branch
   hg revert -r from-branch file
   hg ci -m 'copied single file from from-branch to to-branch

如果要选择该文件的不同部分,则"hg record"很有用.

If you want to select different parts of that file, then "hg record" is useful.

我只是在主目录.hgignore中完成了此操作.

I just did this on my home directory .hgignore.

如果两个分支都对您要保留的文件进行了更改,那么一个肮脏的窍门是使用hg merge创建两个分支的合并,可能/可能在另一个分支上,将其签入,然后进行复制合并和分支之间的单个文件:

If both branches have made changes to a file that you want to keep, a dirty trick would be to create a merge of the two branches using hg merge, possibly/probably on still another branch, check that in, and then copy a single file between the merge and the to-branch:

   hg update -r to-branch
   branch merge-branch
   hg merge -r from-branch
   hg ci -m 'temp merge to be discarded"
   hg update -r to-branch
   hg revert -r merge-branch single-file
   hg ci -m 'merged single-file from from-branch to to-branch"
   hg strip merge-branch

值得一提的是:在分支之间复制单个文件"(或修订,或从修订到合并,或....)的方式是汞还原".即

It is worth mentioning: the way to "copy a single file between branches" (or revisions, or from revision to merge, or....) is "hg revert". I.e.

   hg update -r Where-you-want-to-copy-to
   hg revert -r Where-you-want-to-copy-from file-you-want-to-copy
   ...
   hg ci

出于某种原因,我和我的一些同事发现这个 VERY 令人困惑. "revert" =="copy" ...对于某些使用模式有意义,但并非全部.

For some reason I, and some of my coworkers, find this VERY confusing. "revert"=="copy" ... makes sense for some usage patterns, but not all.

这篇关于Mercurial:在一个仓库中合并分支之间的一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆