我有两个要合并到 mercurial 中的补丁。可悲的是,我删除了导出这些补丁的分支。你们能建议一种合并两个补丁的方法吗?
我在 ubuntu 12.04 机器上使用 Mercurial 2.0.2。
如果您启用了 MQ,并假设您从一个空的补丁队列开始:
> hg qimport patch1 # Import & apply the first patch into a patch queue
> hg qimport patch2 # Import & apply the second patch into a patch queue
> hg qpop; # Pop the second patch (unapply)
> hg qfold patch2 # Fold the second patch into the first (result is called 'patch1')
> hg qexport > new_merged_patch
然后,您可以:
> hg qfinish -a # Convert the currently applied patches (e.g. patch1) to changesets)
或者:
> hg qpop # Pop the merged patch
> hg qdel patch1 # Delete it from the queue
老实说,为此使用 MQ 有点矫枉过正,但它是一个有用的扩展。
如果您将补丁作为补丁文件,您可以将它们相互叠加并根据结果生成补丁:
$ patch -p0 < patch1
$ patch -p0 < patch2
$ hg diff > cumulative.patch
补丁级别-p0
可能会有所不同,具体取决于补丁的结构。