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

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

问题描述

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

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 记录" 很有用.

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

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

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

出于某种原因,我和我的一些同事发现这非常令人困惑.还原"==复制"... 对某些使用模式有意义,但不是全部.

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:在一个 repo 的分支之间合并一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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