在 Mercurial 中,我可以将一个文件的更改应用到同一分支中的另一个文件吗?

发布于 2024-08-29 21:11:27 字数 1006 浏览 4 评论 0原文

在 Subversion 的美好时光中,我有时会使用 svn copy 从现有文件中派生一个新文件。然后,如果它们的共同部分发生了变化,我仍然可以使用 svn merge 来更新派生版本。

要使用 hginit.com 中的示例,假设“guac”配方已经存在,并且我想创建一份“超级鳄梨酱”,其中包含如何向 1000 名狂热足球迷提供鳄梨酱的说明。使用我刚刚描述的过程,我可以:

svn cp guac superguac
svn ci -m "Created superguac by copying guac"
(edit superguac)
svn ci -m "Added instructions for serving 1000 raving soccer fans to superguac"
(edit guac)
svn ci -m "Fixed a typo in guac"
svn merge -r3:4 guac superguac

因此,拼写错误修复将应用于超级鳄梨酱。

Mercurial 提供了一个 hg copy 命令,将文件标记为原始文件的副本,但我不确定存储库结构是否支持类似的工作流程。这是同一个示例,我小心地只编辑了要在合并中使用的提交中的单个文件:

hg cp guac superguac
hg ci -m "Created superguac by copying guac"
(edit superguac)
hg ci -m "Added instructions for serving 1000 raving soccer fans to superguac"
(edit guac)
hg ci -m "Fixed a typo in guac"

我现在想将 guac 中的更改应用到 superguac。这可能吗?如果是这样,正确的命令是什么? Mercurial 中是否有不同的工作流程可以实现相同的结果(仅限于单个分支)?

In the good old days of Subversion, I would sometimes derive a new file from an existing one using svn copy. Then if something changed in sections they had in common, I could still use svn merge to update the derived version.

To use the example from hginit.com, say the "guac" recipe already exists, and I want to create a "superguac" that includes instructions on how to serve guacamole to 1000 raving soccer fans. Using the process I just described, I could:

svn cp guac superguac
svn ci -m "Created superguac by copying guac"
(edit superguac)
svn ci -m "Added instructions for serving 1000 raving soccer fans to superguac"
(edit guac)
svn ci -m "Fixed a typo in guac"
svn merge -r3:4 guac superguac

and thus the typo fix would be applied to superguac.

Mercurial provides an hg copy command that marks a file as a copy of the original, but I'm not sure the repository structure supports a similar workflow. Here's the same example, and I carefully only edit a single file in the commit I want to use in the merge:

hg cp guac superguac
hg ci -m "Created superguac by copying guac"
(edit superguac)
hg ci -m "Added instructions for serving 1000 raving soccer fans to superguac"
(edit guac)
hg ci -m "Fixed a typo in guac"

I now want to apply the change in guac to superguac. Is that possible? If so, what's the right command? Is there a different workflow in Mercurial that achieves the same results (limited to a single branch)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软糖 2024-09-05 21:11:27

没有纯粹的 Mercurial 方法可以跨文件使用补丁,但是如果您的系统上安装了 patch,您可以通过执行一系列 Mercurial 命令来实现基本相同的效果

hg log -p -r tip -I quac | patch superquac

: :“获取最近变更集中应用于文件 quac (-I quac) 的差异 (-p) (-rtip)将其发送到标准输出(hg log),并将其用作作用于文件<的补丁(| patch)命令的输入< em>superquac (superquac)。

There's no pure-mercurial way to go cross-file with your patches, but if patch is installed on your system you could achieve essentially the same thing by following up your series of mercurial commands with:

hg log -p -r tip -I quac | patch superquac

That's essentially saying: "take the diff (-p) that was applied to file quac (-I quac) in the most recent changeset (-r tip) send it to standard output (hg log), and use that as the input to the patch (| patch) command acting on file superquac (superquac).

时光病人 2024-09-05 21:11:27

执行此操作

hg cp guac superguac
hg ci -m "Created superguac by copying guac" # CS1
(edit superguac)
hg ci -m "Added instructions for serving 1000 raving soccer fans to superguac" # CS2
hg up -r revision-before-copy
(edit guac)
hg ci -m "Fixed a typo in guac" #CS3
hg merge # this will transfer the typo-fix both to guac and superguac
hg ci -m "merged typo-fix from guac" # CS4

您可以通过此后存储库看起来像这样来

CS1 <--- CS2 <--------- CS4
  \                     /
   \--<-------- CS3 -<-/

You can do this by

hg cp guac superguac
hg ci -m "Created superguac by copying guac" # CS1
(edit superguac)
hg ci -m "Added instructions for serving 1000 raving soccer fans to superguac" # CS2
hg up -r revision-before-copy
(edit guac)
hg ci -m "Fixed a typo in guac" #CS3
hg merge # this will transfer the typo-fix both to guac and superguac
hg ci -m "merged typo-fix from guac" # CS4

After this the repository looks like this

CS1 <--- CS2 <--------- CS4
  \                     /
   \--<-------- CS3 -<-/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文