在 Mercurial 中,如何从变更集中提取单个文件的更改以应用于另一个分支?

发布于 2024-10-05 03:37:50 字数 150 浏览 0 评论 0原文

我在一个分支上有许多文件的大量提交,我需要将该变更集中的单个文件的修改传输到另一个分支。我该怎么做?我主要使用 TortoiseHg,但命令行解决方案也很好。

如果我转到 TortoiseHg 中的变更集并选择文件,我可以看到我想要传输的差异,但不是实际应用它们的方法。

I have a large commit of many files on one branch, I need to transfer the modifications of a single file in that changeset to another branch. How can I do this? I am mostly using TortoiseHg but commandline solutions are also fine.

If I go to the changeset in TortoiseHg and select the file I can see the diffs I want to transfer, but not a way to actually apply them.

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

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

发布评论

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

评论(2

猫烠⑼条掵仅有一顆心 2024-10-12 03:37:50

您可以使用以下命令获取该文件的补丁:

hg log -r THEREVISIONWITHLOTSOFCHANGES -p -I path/to/justthatfile > justthatfile.patch

然后您可以通过执行以下操作将其导入到您想要的任何分支上:

hg update anotherbranch
hg import --no-commit justthatfile.patch
hg commit

You can get the patch for just that file using:

hg log -r THEREVISIONWITHLOTSOFCHANGES -p -I path/to/justthatfile > justthatfile.patch

which you can then import on whatever branch you want by doing:

hg update anotherbranch
hg import --no-commit justthatfile.patch
hg commit
千纸鹤 2024-10-12 03:37:50

最基本的解决方案是转储文件的补丁,将其应用到当前工作修订版,然后提交(假设您位于存储库的根目录):

$ hg up <revision-to-apply-the-patch-to>
$ hg diff -c <revision-containing-the-patch> <files-to-include> | patch -p0
$ hg ci -m "Transplanting selected changes from <revision-contain...>"

这种方法的缺点是它不是很明显从修订历史记录的角度来看您所做的事情。良好的提交消息在这里会有所帮助,但历史图表没有给出有关移植某些更改的过程的提示。在这种情况下,合并和恢复可能是一个更好的解决方案:

$ hg up <revision-to-apply-the-patch-to>
$ hg merge -r <revision-containing-the-patch>
$ hg revert --no-backup <files-to-exclude>
$ hg ci -m "Merge in changes of <files-to-include>"

可能有更多的解决方案可以做到这一点——我首先想到的是这两个。

The most basic solution is to dump the patch of the file, apply it to the current working revision, and commit it (assuming you're at the root of the repository):

$ hg up <revision-to-apply-the-patch-to>
$ hg diff -c <revision-containing-the-patch> <files-to-include> | patch -p0
$ hg ci -m "Transplanting selected changes from <revision-contain...>"

The drawback of this method is that it isn't very obvious what you've done from a revision history perspective. A good commit message helps here, but the history graph gives no hint about the process of transplanting some changes. In that case merging and reverting may be a better solution:

$ hg up <revision-to-apply-the-patch-to>
$ hg merge -r <revision-containing-the-patch>
$ hg revert --no-backup <files-to-exclude>
$ hg ci -m "Merge in changes of <files-to-include>"

Probably there are more solutions to do this -- these two came to my mind first.

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