在 Mercurial 中,hg graft 和 hg rebase 有什么区别

In Mercurial what's the difference between hg graft and hg rebase

我知道 Rebase is a (bundled) extension, while Graft is a core feature (that replaced the Transplant(捆绑)扩展。

graft 记录为:

copy changes from other branches onto the current branch

This command uses Mercurial's merge logic to copy individual changes from other branches without merging branches in the history graph. This is sometimes known as 'backporting' or 'cherry-picking'.

rebase 记录为:

Rebase allows moving commits around in Mercurial's history (using a series of internal merges). This has many uses:

  • moving changesets between branches
  • "linearizing" history
  • reordering changesets
  • collapsing multiple changes into one changeset

两者似乎都使用合并在分支之间移动或复制变更集。

移植副本。变基移动。但是rebase --keep份。

很多时候我似乎都可以实现复制变更集的目标。 我用哪一个重要吗?我什么时候应该更喜欢一个?

例如应该只在复制到不同的 named 分支时才使用 graft 吗?或者仅当只有一个变更集时?


编辑:rebase 可能是 graft 的潜在不安全超集,但只能在开发期间与 draft 变更集一起使用以编辑本地历史记录,而 graft 是 rebase 的安全子集,可以在维护期间与 public 变更集一起用于向后移植?

正如您在问题中指出的那样,

hg graft 允许 "cherry-picking,"。例如,您可以 运行 hg graft -D "2085::2093 and not 2091" 仅复制 一些 来自另一个修订版的更改。相比之下,hg rebase(带或不带 --keep)将获取您指定的任何变更集及其后代变更的 所有

此外,rebase 允许您折叠变更集(使用 --collapse)。据我所知,graft 没有。

我注意到的另一个区别是:hg graft --edit 123 允许您将修订版 123 移植到工作目录并编辑提交消息。我找不到 hg rebase 等价物。不过,我应该指出,hg histedit 还允许在变基时编辑提交消息。

可能还有其他我没有想到的差异。 SO 社区:请随时在评论中指出这些问题,我很乐意修改此答案以使其更加完整。

有关详细信息,请参阅 the graft documentation and the Rebase Extension documentation