Jox*_*Jox 49 version-control mercurial dvcs branching-and-merging
当我在Hg repo中有两个分支时,如何只将一个文件与另一个分支合并,而没有将变更集中的所有其他文件合并?
是否可以仅合并某些文件,而不是整个变更集?
Kra*_*lew 55
警告:@Martin_Geisler推荐的这种"虚拟合并"可能真的搞砸了你,如果以后你想要对这两个分支进行真正的合并.将记录虚拟合并,并说您合并到您进行虚拟合并的分支 - 您将看不到更改.或者,如果您合并到另一个分支,则其他分支上的更改将被撤消.
如果您只想将整个文件从一个分支复制到另一个分支,您只需执行以下操作:
hg update -r to-branch
hg revert -r from-branch file
hg ci -m 'copied single file from from-branch to to-branch
Run Code Online (Sandbox Code Playgroud)
如果要选择该文件的不同部分,则"hg record"非常有用.
我刚刚在我的主目录.hgignore上做了这个.
如果两个分支都对您要保留的文件进行了更改,那么一个肮脏的技巧就是使用hg merge创建两个分支的合并,可能/可能在另一个分支上,检查其中,然后复制单个文件合并与分支之间:
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
Run Code Online (Sandbox Code Playgroud)
值得一提的是:"在分支之间复制单个文件"(或修订,或从修订到合并,或......)的方式是"hg revert".即
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
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我和我的一些同事发现这非常令人困惑."revert"=="copy"......对某些使用模式有意义,但不是全部.
Mar*_*ler 18
不.Mercurial在变更集的基础上工作.
但是你可以进行" 虚拟合并 ",忽略来自其中一个分支的传入更改.在提交之前,您可以将所选文件还原为您想要的任何状态:
% HGMERGE=internal:local hg merge # keep my files
% hg revert --rev other-branch a.txt # update a.txt to other branch
% hg commit -m 'Dummy merge to pick a.txt from other-branch.'
Run Code Online (Sandbox Code Playgroud)
也许这会对你有所帮助.