使用 Mercurial,我需要在分支之前提交到主分支吗?

发布于 2024-12-04 16:25:47 字数 162 浏览 0 评论 0原文

使用 Mercurial 存储库,在初始化它之后,我是否需要在创建另一个命名分支之前先提交到 master 分支,或者我可以这样做:

hg init
hg branch develop

然后提交到开发分支,然后在某个阶段将开发合并到主分支中。

With a mercurial repository, after initialising it, do I need to commit to the master branch first, before creating another named branch, or can I do:

hg init
hg branch develop

and then commit onto the develop branch, before at some stage merging develop into the master.

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

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

发布评论

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

评论(1

橙幽之幻 2024-12-11 16:25:47

Mercurial 确实没有主分支的概念;它们都是平等的,并且所有 hg 变更集都属于一个且仅一个分支。有一个约定将初始分支命名为default,并且在创建新分支之前一直使用该名称,但您不需要使用该名称。在您的情况下,由于初始提交是对名为 develop 的分支进行的,因此不存在其他分支名称,包括 default,直到您随后创建并提交一个分支。

不使用分支命令:

$ hg init
$ hg branches
$ touch a
$ hg add
adding a
$ hg comm -m 'initial commit to default'
$ hg branches
default                        0:c3eac81383bd

使用 branch 命令:

$ hg init
$ hg branch develop
marked working directory as branch develop
$ touch a
$ hg add
adding a
$ hg commit -m 'on develop'
$ hg branches
develop                        0:f0170c7bcdcf
$ hg branch default
marked working directory as branch default
$ touch b
$ hg add b
$ hg commit -m 'on default'
$ hg branches
default                        1:0668d80655ff
develop                        0:f0170c7bcdcf (inactive)
$ ls
a  b
$ hg update develop  # change working directory back to develop branch
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ ls
a

Mercurial really doesn't have the concept of a master branch; they are all equal and all hg changesets belong to one and only one branch. There is a convention of naming the initial branch as default and that name is used until you create a new branch, but you don't need to use that name. In your case, since the initial commit is made to a branch named develop, no other branch names exist, including default, until you subsequently create and commit one.

Without using a branch command:

$ hg init
$ hg branches
$ touch a
$ hg add
adding a
$ hg comm -m 'initial commit to default'
$ hg branches
default                        0:c3eac81383bd

Using a branch command:

$ hg init
$ hg branch develop
marked working directory as branch develop
$ touch a
$ hg add
adding a
$ hg commit -m 'on develop'
$ hg branches
develop                        0:f0170c7bcdcf
$ hg branch default
marked working directory as branch default
$ touch b
$ hg add b
$ hg commit -m 'on default'
$ hg branches
default                        1:0668d80655ff
develop                        0:f0170c7bcdcf (inactive)
$ ls
a  b
$ hg update develop  # change working directory back to develop branch
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ ls
a
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文