像我可以使用TortoiseHg一样,如何合并以摆脱Mercurial命令行的束缚? [英] How to merge to get rid of head with Mercurial command line, like I can do with TortoiseHg?
问题描述
我的问题是这个
- 如果我的Mercurial存储库中有两个主管(带有更改的分支),并且我想摆脱其中一个,但是放弃该分支中的所有更改,而不是将它们合并到另一个中,我可以不会去除那些变更集,所以我必须合并,如何使用命令行客户端来做到这一点?
如果我的Mercurial存储库中有两个负责人,并且使用TortoiseHg作为客户端,则该存储库可能如下所示:
If I have two heads in my Mercurial repository, and use TortoiseHg as my client, the repository might look like this:
然后我可以通过合并和丢弃来摆脱test2
头.首先,我将更新到想要保留的头部(在本例中为test3
,在上图中,它已经是我的工作文件夹的当前父文件夹).然后,我将右键单击并选择与...合并":
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):
此合并完成后,test2
头中的所有更改都已被放弃,我可以提交.头部现在已经消失了,但是变更集仍然是历史的一部分.
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.
我的问题是:我如何仅使用命令行客户端来做同样的事情?我找不到hg merge
命令的任何匹配选项:
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
编辑:debugsetparents表现良好:
Edit: debugsetparents worked nicely:
hg debugsetparents . 1
hg commit -m "merged to get rid of changeset #1"
<罢工>
编辑:根据答案之一尝试使用--tool internal:local
:
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
执行输出:
[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\repo\*
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
这里,在第二个变更集中引入的变更(修订号为1的变更)现在存在于合并的变更集中.这不是我想要的.
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.
推荐答案
根据TortoiseHG的源,当您选中Discard all changes from merge target (other) revision
时,它会使用hg debugsetparents
命令:
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
要使用:
hg up <revision-to-keep>
hg debugsetparents <revision-to-keep> <revision-to-throw-away>
hg commit -m "Merge to discard ..."
这篇关于像我可以使用TortoiseHg一样,如何合并以摆脱Mercurial命令行的束缚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!