还有其他方法可以去除多个头吗?

发布于 2024-11-26 21:48:04 字数 300 浏览 0 评论 0原文

假设我有这个:

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 技术交流群。

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

发布评论

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

评论(2

臻嫒无言 2024-12-03 21:48:04

是的,还有另一种方法。从上面的示例中,hg glog 的输出看起来有点像这样:

@  changeset:   2:925573c7103c
|  tag:         tip
|  parent:      0:4fe26dfe856d
|  user:        Joel B Fant
|  date:        Thu Jul 28 23:20:45 2011 -0400
|  summary:     c
|
| o  changeset:   1:9dc928176506
|/   user:        Joel B Fant
|    date:        Thu Jul 28 23:20:24 2011 -0400
|    summary:     b
|
o  changeset:   0:4fe26dfe856d
   user:        Joel B Fant
   date:        Thu Jul 28 23:20:12 2011 -0400
   summary:     a

如果您克隆 test指定修订版,它只会克隆该修订版及其祖先。因此,如果您的存储库目录是 TwoHeadsMightNotBeBetter,您可以转到其父目录并发出:

hg clone TwoHeadsMightNotBeBetter OneHeadIsFine -r 925573c7103c

我在其中指定了变更集 id,但您也可以使用 -r 2 代替,或者甚至 -rtip 因为它当前是该存储库的提示。现在,当您进入新克隆并执行 hg glog 时,您只有一个头:

@  changeset:   1:925573c7103c
|  tag:         tip
|  user:        Joel B Fant
|  date:        Thu Jul 28 23:20:45 2011 -0400
|  summary:     c
|
o  changeset:   0:4fe26dfe856d
   user:        Joel B Fant
   date:        Thu Jul 28 23:20:12 2011 -0400
   summary:     a

如果您有 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:

@  changeset:   2:925573c7103c
|  tag:         tip
|  parent:      0:4fe26dfe856d
|  user:        Joel B Fant
|  date:        Thu Jul 28 23:20:45 2011 -0400
|  summary:     c
|
| o  changeset:   1:9dc928176506
|/   user:        Joel B Fant
|    date:        Thu Jul 28 23:20:24 2011 -0400
|    summary:     b
|
o  changeset:   0:4fe26dfe856d
   user:        Joel B Fant
   date:        Thu Jul 28 23:20:12 2011 -0400
   summary:     a

If you clone test but specify a revision, it will only clone that revision and its ancestors. So if your repo's directory is TwoHeadsMightNotBeBetter, you can go to its parent directory and issue:

hg clone TwoHeadsMightNotBeBetter OneHeadIsFine -r 925573c7103c

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 do hg glog, you have only one head:

@  changeset:   1:925573c7103c
|  tag:         tip
|  user:        Joel B Fant
|  date:        Thu Jul 28 23:20:45 2011 -0400
|  summary:     c
|
o  changeset:   0:4fe26dfe856d
   user:        Joel B Fant
   date:        Thu Jul 28 23:20:12 2011 -0400
   summary:     a

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 on hg pull to pull specific branches.

凤舞天涯 2024-12-03 21:48:04

您还可以对包含 b 的变更集(本例中为变更集 1)执行虚拟合并:

$ hg --config ui.merge=internal:fail merge 1
resolving manifests
getting b
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

$ hg revert --all --no-backup --rev .
removing b

$ hg status
R b

$ hg commit -m "Dummy merge -- eliminate b"
committed changeset 3:c163151f19df

$ ls
a  c

请注意,在这种情况下,您尚未重写任何历史记录或创建任何新的存储库 - 如果 < code>b 已经被推送到集中存储库并被其他人拉取。

You can also perform a dummy merge of the changeset containing b (changeset 1 in this case):

$ hg --config ui.merge=internal:fail merge 1
resolving manifests
getting b
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

$ hg revert --all --no-backup --rev .
removing b

$ hg status
R b

$ hg commit -m "Dummy merge -- eliminate b"
committed changeset 3:c163151f19df

$ ls
a  c

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.

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