HG的分支如何开发?
我想在 hg 项目中做一些实验工作。所以我想创建分支并提交它。如果实验有效,我可以将其合并回主分支。
在 git 中,我可以
$ git branch experimental
$ git checkout experimental
(edit file)
$ git commit -a
$ git checkout master
阅读 指南到 Mercurial 中的分支。它说hg分支功能
。但下一步是什么? 我不跟。
I would like to do some experimental work in a hg project. So I would like to create branch, commit to it. And if the experiment works, I can merge it back to main branch.
In git, I can do
$ git branch experimental
$ git checkout experimental
(edit file)
$ git commit -a
$ git checkout master
I've read A Guide to Branching in Mercurial. It said hg branch feature
. But what is next?
I don't follow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先请注意,
gitbranch
与hg 分支
。使用hgbranch
创建的分支是永久的,并且存在于全局名称空间中,而使用gitbranch
创建的分支是暂时的。与gitbranch
最接近的等效项是hg bookmark
:书签可以重命名和删除,其行为更像 Git 分支。我最近编写了Mercurial 书签指南。将此与命名分支指南进行比较。两个指南都包含如何在 Mercurial 中使用(命名)分支来跟踪开发的工作示例。它展示了如何合并分支以及如何在完成后关闭它们或删除书签。
First note that
git branch
is different fromhg branch
. Branches created withhg branch
are permanent and live in a global name space, whereas branches made withgit branch
are transient. The nearest equivalent ofgit branch
ishg bookmark
: bookmarks can be renamed and deleted and behave more like Git-branches.I've recently written a guide for Mercurial bookmarks. Compare this with the named branch guide. Both guides contain worked examples of how to use (named) branches in Mercurial for keeping track of the development. It shows how to merge branches and how to close them or delete the bookmark when you are done.
如果它不是一个大功能(即分支不必有名称),那么它非常简单。
假设您的存储库位于变更集 X。您可以按照自己喜欢的方式处理该功能,提交,提交,提交,如果您对结果感到满意,请继续,就好像您知道它会一直工作一样。 ;) 如果您不满意,请执行
hg update X
并从那里继续开发。您在实验中所做的所有工作都将成为匿名分支。奇怪的是,它出现 Git 没有提供这样一种处理匿名分支的方法,这可能会让您感到困惑。
If it's not a big feature (i.e. the branch doesn't have to have a name), it's quite simple.
Let's say your repository is at changeset X. You work on the feature as much as you like, commit, commit, commit and if you're happy with the result, continue as if you knew it would work all along. ;) If you aren't happy, do a
hg update X
and continue development from there. All the work you did on your experiment will become an anonymous branch.Strangely enough, it appears that Git doesn't provide such a way to work with anonymous branches which is what might be confusing you.