还有其他方法可以去除多个头吗?
假设我有这个:
hg init
touch a
hg add a
hg commit -m a
touch b
hg add b
hg commit -m b
hg up -r 0
touch c
hg add c
hg commit -m c
由于上次提交,现在我将有多个头。例如,如果我想保留最后一个头,即由提交 c 创建的头(有效地丢弃 b 以及第一个之后进行的所有其他提交),我该怎么做?我玩了一下 mq 的 strip
命令,我能够实现我想要的,但我想知道是否还有其他方法。
Let's say I have this:
hg init
touch a
hg add a
hg commit -m a
touch b
hg add b
hg commit -m b
hg up -r 0
touch c
hg add c
hg commit -m c
Now I will have multiple heads, because of the last commit. If, for example I want to keep the last head, the one created by commit c
( effectively discarding b, and all other commits made after the first ) , how could I do it? I played a little with mq's strip
command, and I'm able to achieve what I want, but I'd like to know if there's another way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,还有另一种方法。从上面的示例中,
hg glog
的输出看起来有点像这样:如果您克隆
test
但指定修订版,它只会克隆该修订版及其祖先。因此,如果您的存储库目录是TwoHeadsMightNotBeBetter
,您可以转到其父目录并发出:我在其中指定了变更集 id,但您也可以使用
-r 2
代替,或者甚至-rtip
因为它当前是该存储库的提示。现在,当您进入新克隆并执行hg glog
时,您只有一个头:如果您有 3 个头并想保留 2 个,那就有点不同了。您必须使用
-r
克隆其中之一,并在hg pull
上指定-r
来拉取特定分支。Yes, there is another way. From your example above, the output of
hg glog
looks a bit like this:If you clone
test
but specify a revision, it will only clone that revision and its ancestors. So if your repo's directory isTwoHeadsMightNotBeBetter
, you can go to its parent directory and issue:I specified changeset id in that, but you could also use
-r 2
instead, or even-r tip
since it is currently the tip of that repo. Now when you go into the new clone and dohg glog
, you have only one head:If you had 3 heads and wanted to keep 2, it would be a little different. You'd have to clone one of them with
-r
and the also specify-r
onhg pull
to pull specific branches.您还可以对包含
b
的变更集(本例中为变更集 1)执行虚拟合并:请注意,在这种情况下,您尚未重写任何历史记录或创建任何新的存储库 - 如果 < code>b 已经被推送到集中存储库并被其他人拉取。
You can also perform a dummy merge of the changeset containing
b
(changeset 1 in this case):Note that in this case you haven't rewritten any history or created any new repos -- particularly important if
b
had already been pushed to a centralized repo and pulled by others.