Hg 几乎犯了错误的分支

发布于 2024-12-04 13:13:31 字数 83 浏览 1 评论 0原文

我有一个未提交的变更集。我注意到我目前位于错误的分支上,因此在提交之前,我想切换到我想要的分支,然后提交。

在汞中实现这一目标有多困难?

I have a changeset that is uncommitted. I noticed that I am currently on the wrong branch, so before I commit this, I would like to switch to the branch that I meant to be on, then commit.

How difficult is this to achieve in Hg?

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

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

发布评论

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

评论(4

物价感观 2024-12-11 13:13:31

如果当前父修订版和目标修订版之间存在线性路径,那么您可以直接发布

hg update right-branch

,Mercurial 会将工作副本中的更改合并到目标修订版中。

这是使用完全合并工具机制完成的,因此会考虑重命名之类的事情,并且在发生冲突时您将获得三向合并程序。基于搁置和差异的方法缺乏这一点,并且需要您使用 .rej 文件手动修复冲突。您甚至可以使用 hgsolve --list 查看当前合并状态,并重新合并选定的文件,因为 Mercurial 会为您进行必要的备份。

如果没有线性路径,您将收到此警告:

abort: crosses branches (merge branches or use --clean to discard changes)

然后,您可以通过首先更新回共同祖先,然后再次向前更新来获得所需的内容。我不是 100% 确定我们为什么发出此警告,但如果您好奇的话,搜索邮件列表档案应该会给您答案。

If there is a linear path between the current parent revision and the target revision, then you can just issue

hg update right-branch

and Mercurial will merge the changes in your working copy into the target revision.

This is done using the full merge tool machinery so things like renames are taken into account and you'll get a three-way merge program in case of conflicts. The shelve- and diff-based approaches lack this and requires you to fix conflicts by hand using .rej files. You can even see the current merge status with hg resolve --list and re-merge selected files since Mercurial makes the necessary backups for you.

If there is not a linear path, you will get this warning:

abort: crosses branches (merge branches or use --clean to discard changes)

You can then get what you want by first updating back to a common ancestor, and then updating forward again. I'm not 100% sure why we issue this warning, but searching the mailinglist archives should give you the answer if you're curious.

墨小墨 2024-12-11 13:13:31

如果您想在不使用搁置扩展的情况下执行此操作,请执行以下操作:

hg diff --git > ../work_in_progress.patch
hg up desired-branch
hg import --no-commit ../work_in_progress.patch

其中 ../work_in_progress.patch 可以是您想要的任何路径(我通常将补丁存储在我的存储库上方)并且 < code>desired-branch 是您实际想要应用更改的分支。

请注意,如果您所在的分支和您将要使用的分支差异很大,以至于您的补丁无法顺利应用,那么我找到的任何解决方案都会开始崩溃。在这种情况下,您开始必须手动解决冲突。

If you'd like to do this without the shelve extension, do the following:

hg diff --git > ../work_in_progress.patch
hg up desired-branch
hg import --no-commit ../work_in_progress.patch

Where ../work_in_progress.patch can be any path you want (I usually store my patches just above my repository) and desired-branch is the branch you actually want to apply your changes to.

Note that any solution I've found starts to fall apart if the branch you are on and the branch you're going to are different enough that your patch doesn't apply smoothly. In that case, you start getting into having to manually resolve conflicts.

嘿嘿嘿 2024-12-11 13:13:31

如果您使用 TortoiseHg,则可以通过 THG 的搁置功能轻松实现 (http ://tortoisehg.bitbucket.io/manual/2.9/shelve.html)。在提交对话框中,只需单击“搁置”按钮(其图标是一个叠加有 Z 的文件),然后单击向右双箭头即可搁置所有更改。关闭搁置对话框,更新到正确的变更集,打开搁置对话框并单击左双箭头取消搁置它们。

如果您不使用 THG,则可以安装 hgshelve 扩展 (https://www.mercurial -scm.org/wiki/ShelveExtension),但我不熟悉它。

似乎您也可以使用 Mercurial 队列获得相同的结果(http:// Mercurial.808500.n3.nabble.com/Shelve-extension-td802439.html)。

If you're using TortoiseHg, it's very easy to achieve with the shelve ability of THG (http://tortoisehg.bitbucket.io/manual/2.9/shelve.html). In the commit dialog, just click the Shelve button (whose icon is a file with a Z superimposed) then the double right arrow to shelve all changes. Close the shelve dialog, update to the correct changeset, open the shelve dialog and click the double left arrow to unshelve them.

If you're not using THG, you can install the hgshelve extension (https://www.mercurial-scm.org/wiki/ShelveExtension), but I'm not familiar with it.

Seems you can also achieve the same result with Mercurial Queues (http://mercurial.808500.n3.nabble.com/Shelve-extension-td802439.html).

望笑 2024-12-11 13:13:31

不幸的是,Mercurial 不支持开箱即用的搁置,因此您需要进行临时提交并使用 rebasetramsplant 将其转移到正确的分支,或者进行 diff 和手动应用它。您还可以使用第 3 方搁置扩展,请参阅 https://www.mercurial-scm。 org/wiki/ShelveExtensionhttps://www.mercurial-scm.org/wiki/AtticExtension

Unfortunately Mercurial doesn't support shelving out of the box so you need to make a temporary commit and the transfer it to the proper branch using rebase or tramsplant or make a diff and apply it manually. You can also use a 3rd-party shelve extension, see https://www.mercurial-scm.org/wiki/ShelveExtension and https://www.mercurial-scm.org/wiki/AtticExtension

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