如何合并以摆脱使用 Mercurial 命令行的头,就像我可以使用 TortoiseHg 一样? [英] How to merge to get rid of head with Mercurial command line, like I can do with TortoiseHg?

查看:16
本文介绍了如何合并以摆脱使用 Mercurial 命令行的头,就像我可以使用 TortoiseHg 一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:

  • 如果我的 Mercurial 存储库中有两个 head(有更改的分支),并且我想删除其中一个,但丢弃该分支中的所有更改而不是将它们合并到另一个中,我可以不去掉那些变更集所以我必须合并,我该如何使用命令行客户端来做到这一点?
<小时>

如果我的 Mercurial 存储库中有两个 head,并使用 TortoiseHg 作为我的客户端,则存储库可能如下所示:

然后我可以通过合并和丢弃来摆脱 test2 头.首先,我会更新我想要保留的头部(在这种情况下为 test3,在上图中,它已经是我的工作文件夹的当前父文件夹).然后我会右键单击并选择与...合并":

在弹出的对话框中,我会选择放弃来自合并目标的更改(即我想放弃所有更改的分支):

这次合并完成后,test2 头部的所有更改都被丢弃了,我可以提交了.头部现在已经消失,但变更集仍然是历史的一部分.

我的问题是:如何仅使用命令行客户端执行相同的操作?我找不到 hg merge 命令的任何匹配选项:

<前>hg 合并 [-P] [-f] [[-r] 修订版]将工作目录与另一个修订版合并... 剪切文本选项:-f --force 强制合并未完成的更改-t --tool VALUE 指定合并工具-r --rev REV 版本合并-P --preview 要合并的审阅修订(不执行合并)--mq 操作补丁库使用hg -v help merge"来显示全局选项

<小时>

编辑:debugsetparents 运行良好:

<前>hg debugsetparents .1hg commit -m 合并以摆脱变更集 #1"

<打击>编辑:根据以下答案之一尝试使用 --tool internal:local:

@echo off设置本地如果存在 repo rd/s/q repohg 初始化仓库光盘回购rem 修订版 0echo >test1.txthg commit -m "test1" --addremoverem 修订版 1echo >test2.txthg commit -m "test2" --addremoverem 修订版 2汞更新 0echo >test3.txthg commit -m "test3" --addremoverem 现在让我们通过合并消除修订版 1 中的更改hg 合并 --tool 内部:本地 -r 1hg commit -m "合并"目录

执行输出:

<前>[C:Temp] :test添加 test1.txt添加 test2.txt更新了 0 个文件,合并了 0 个文件,删除了 1 个文件,未解决了 0 个文件添加 test3.txt创造了新的头更新 1 个文件,合并 0 个文件,删除 0 个文件,未解析 0 个文件(分支合并,不要忘记提交)驱动器 C 中的卷未标记序列号为 0e17:6abaC:Temp epo* 目录16.11.2010 20:05 .16.11.2010 20:05 ..16.11.2010 20:05 .hg16.11.2010 20:05 13 test1.txt16.11.2010 20:05 13 test2.txt16.11.2010 20:05 13 test3.txt3 个文件和 3 个目录中的 39 个字节分配了 12 288 个字节66 600 316 928 字节空闲

此处在第二个变更集中引入的变更(修订号为 1 的变更)现在出现在合并变更集中.这不是我想要的.

解决方案

根据 TortoiseHG 的 source,当你勾选Discard all changes from merge target (other) revision,它使用hg debugsetparents命令:

hg debugsetparents REV1 [REV2]手动设置当前工作目录的父目录这对于编写存储库转换工具很有用,但应谨慎使用.成功返回 0.使用hg -v help debugsetparents"显示全局选项

使用:

 hg up hg debugsetparents <revision-to-keep><修改后丢弃>hg commit -m "合并丢弃..."

My question is this:

  • If I have two heads (branches with changes) in my Mercurial repository, and I'd like to get rid of one of them, but discard all the changes from that branch instead of merging them into the other, and I can't strip out those changesets so I have to merge, how can I do that with the command line client?

If I have two heads in my Mercurial repository, and use TortoiseHg as my client, the repository might look like this:

Then I can get rid of the test2 head by doing a merge and discarding. First I would update to the head I'd like to keep (test3 in this case, which in the image above is already the current parent of my working folder). Then I would right-click and select "Merge with...":

and in the dialog that pops up I would choose to discard the changes from the merge target (ie. the branch I'd like to discard all the changes from):

After this merge has gone through, all the changes in the test2 head has been discarded, and I can commit. The head has now disappeared, but the changeset is still part of history.

My question is this: How can I do the same thing using only the command line client? I can't find any matching options to the hg merge command:

hg merge [-P] [-f] [[-r] REV]

merge working directory with another revision

... snipped text

options:

 -f --force       force a merge with outstanding changes
 -t --tool VALUE  specify merge tool
 -r --rev REV     revision to merge
 -P --preview     review revisions to merge (no merge is performed)
    --mq          operate on patch repository

use "hg -v help merge" to show global options


Edit: debugsetparents worked nicely:

hg debugsetparents . 1
hg commit -m "merged to get rid of changeset #1"

Edit: Attempt to use the --tool internal:local according to one of the answers:

@echo off

setlocal
if exist repo rd /s /q repo
hg init repo
cd repo

rem revision 0
echo >test1.txt
hg commit -m "test1" --addremove

rem revision 1
echo >test2.txt
hg commit -m "test2" --addremove

rem revision 2
hg update 0
echo >test3.txt
hg commit -m "test3" --addremove

rem now let's get rid of change in revision 1 with merge
hg merge --tool internal:local -r 1
hg commit -m "merged"

dir

output of execution:

[C:Temp] :test
adding test1.txt
adding test2.txt
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
adding test3.txt
created new head
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

 Volume in drive C is unlabeled      Serial number is 0e17:6aba
 Directory of  C:Temp
epo*

16.11.2010  20:05             .
16.11.2010  20:05             ..
16.11.2010  20:05             .hg
16.11.2010  20:05              13  test1.txt
16.11.2010  20:05              13  test2.txt
16.11.2010  20:05              13  test3.txt
                39 bytes in 3 files and 3 dirs    12 288 bytes allocated
    66 600 316 928 bytes free

Here the changes introduced in the 2nd changeset (the one with revision number 1), is now present in the merged changeset. This is not what i wanted.

解决方案

According to TortoiseHG's source, when you check Discard all changes from merge target (other) revision, it uses the hg debugsetparents command:

hg debugsetparents REV1 [REV2]

manually set the parents of the current working directory

    This is useful for writing repository conversion tools, but should be used with care.

    Returns 0 on success.

use "hg -v help debugsetparents" to show global options

To use:

    hg up <revision-to-keep>
    hg debugsetparents <revision-to-keep> <revision-to-throw-away>
    hg commit -m "Merge to discard ..."

这篇关于如何合并以摆脱使用 Mercurial 命令行的头,就像我可以使用 TortoiseHg 一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆