Mercurial,“用书签进行分支”

发布于 2024-10-05 10:53:22 字数 2055 浏览 4 评论 0原文

我阅读了此文档:Mercurial 分支指南< /a>,特别是标题为 使用书签进行分支

它说:

现在,您在当前变更集中的两个分支有了两个书签(本质上是一个标签)。

要切换到这些分支之一,您可以使用 hg update feature 更新到该分支的提示变更集,并将自己标记为在该分支上工作。当您提交时,它会将书签移动到新创建的变更集。

我尝试了这个,但它最终同时移动了两个书签。

该指南是错误的、过时的还是我做错了什么?请注意,我知道在单独的分支上添加书签只会移动与我当前正在处理的分支相关的书签,但是该指南(很多人说这是对此的明确指南)特别说明了上面的文本,这表明它应该通过“告诉”Mercurial 我正在处理哪个书签(分支)来工作。

但测试表明情况并非如此。

有什么想法吗?

例子:

> hg init
> echo 1 >test.txt
> hg commit -m "initial" --addremove
adding test.txt

> hg bookmark main
> hg bookmark feature
> hg log
changeset:   0:c56ceb49ee20
tag:         feature
tag:         main
tag:         tip
user:        Lasse V. Karlsen <[email protected]>
date:        Tue Nov 30 23:06:16 2010 +0100
summary:     initial

> hg update feature
0 files updated, 0 files merged, 0 files removed, 0 files unresolved

> echo 2 >test2.txt
> hg commit -m "feature 1" --addremove
adding test2.txt

> hg log
changeset:   1:9f2f5869b57b
tag:         feature                             <---- both were moved
tag:         main                                <----
tag:         tip
user:        Lasse V. Karlsen <[email protected]>
date:        Tue Nov 30 23:06:45 2010 +0100
summary:     feature 1

changeset:   0:c56ceb49ee20
user:        Lasse V. Karlsen <[email protected]>
date:        Tue Nov 30 23:06:16 2010 +0100
summary:     initial

I read this document: A Guide to Branching with Mercurial, specifically the section titled Branching with Bookmarks.

It says:

Now you’ve got two bookmarks (essentially a tag) for your two branches at the current changeset.

To switch to one of these branches you can use hg update feature to update to the tip changeset of that branch and mark yourself as working on that branch. When you commit, it will move the bookmark to the newly created changeset.

I tried this, but it ended up moving both bookmarks at the same time.

Is that guide wrong, outdated, or did I do something wrong? Note that I know that having bookmarks on separate branches only moves the bookmark related to the branch I'm currently working on, but that guide (which a lot of people says is the definite guide to this) specifically says the above text, which indicates that it should've worked by "telling" Mercurial which bookmark (branch) I'm working on.

Testing shows otherwise though.

Any ideas?

Example:

> hg init
> echo 1 >test.txt
> hg commit -m "initial" --addremove
adding test.txt

> hg bookmark main
> hg bookmark feature
> hg log
changeset:   0:c56ceb49ee20
tag:         feature
tag:         main
tag:         tip
user:        Lasse V. Karlsen <[email protected]>
date:        Tue Nov 30 23:06:16 2010 +0100
summary:     initial

> hg update feature
0 files updated, 0 files merged, 0 files removed, 0 files unresolved

> echo 2 >test2.txt
> hg commit -m "feature 1" --addremove
adding test2.txt

> hg log
changeset:   1:9f2f5869b57b
tag:         feature                             <---- both were moved
tag:         main                                <----
tag:         tip
user:        Lasse V. Karlsen <[email protected]>
date:        Tue Nov 30 23:06:45 2010 +0100
summary:     feature 1

changeset:   0:c56ceb49ee20
user:        Lasse V. Karlsen <[email protected]>
date:        Tue Nov 30 23:06:16 2010 +0100
summary:     initial

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

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

发布评论

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

评论(2

过潦 2024-10-12 10:53:22

如果我没猜错的话,您希望只需要您已更新的书签才能在下一次提交中移动。为此,书签扩展具有 track.current 选项。

来自 BookmarksExtension

默认情况下,当多个书签指向同一个变更集时,它们都会一起前进。通过将以下配置选项添加到 .hgrc 中,可以获得更像 Git 的体验

[bookmarks]
track.current = True

在您的示例中,这会将 main 书签保留在修订版 0 处。

如果 track.current启用 选项后,当前活动书签在 hg bookmarks 的输出中用星号注释。

更新:自 Mercurial 1.8 起,默认行为是仅移动当前书签,即不再需要上述选项[1]

If I got you right, you want only the bookmark you've updated to move on the next commit. For this purpose the bookmarks extensions has the track.current option.

From BookmarksExtension:

By default, when several bookmarks point to the same changeset, they will all move forward together. It is possible to obtain a more Git-like experience by adding the following configuration option to your .hgrc

[bookmarks]
track.current = True

In your example, this would keep the main bookmark at revision 0.

If the track.current option is enabled, the currently active bookmark is annotated with an asterisk in the output of hg bookmarks.

UPDATE: Since Mercurial 1.8 the default behavior is to only move the current bookmark, i.e. the above mentioned option is not needed anymore [1].

一紙繁鸢 2024-10-12 10:53:22

如果您阅读了 BookmarksExtension 的说明,它会显示:

书签是对提交的引用,在进行新提交时会自动更新。

和:

由于书签在提交它们指向的变更集时会自动更新,因此它们对于跟踪不同的头特别有用。

就您而言,当您创建两个书签时,存储库中只有一个头。如果您使用如下所示的序列,它应该按您的预期工作:

hg init foo
# edit, edit, edit
hg commit -A -m "root"
hg bookmark main
# edit, edit, edit ...
hg commit -m "main 1"
hg update 0
# edit, edit edit
hg bookmark feature
hg commit -m "feature 1"

If you read the description of the BookmarksExtension, it says:

Bookmarks are references to commits that are automatically updated when new commits are made.

and:

Since bookmarks are automatically updated when commiting to the changeset they are pointing to, they are especially useful to keep track of different heads.

In your case, you only had one head in the repository at the time you created both bookmarks. If you use a sequence like the following, it should work as you expect:

hg init foo
# edit, edit, edit
hg commit -A -m "root"
hg bookmark main
# edit, edit, edit ...
hg commit -m "main 1"
hg update 0
# edit, edit edit
hg bookmark feature
hg commit -m "feature 1"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文