在 Mercurial 中,我可以将一个文件的更改应用到同一分支中的另一个文件吗?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有纯粹的 Mercurial 方法可以跨文件使用补丁,但是如果您的系统上安装了 patch,您可以通过执行一系列 Mercurial 命令来实现基本相同的效果
: :“获取最近变更集中应用于文件 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: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
).执行此操作
您可以通过此后存储库看起来像这样来
You can do this by
After this the repository looks like this