与Mercurial SCM分支 [英] Branching with Mercurial SCM

查看:95
本文介绍了与Mercurial SCM分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,现在我正在学习Ruby on Rails,并且正在阅读《用Rails进行敏捷Web开发》一书.我还决定要尝试一下Mercurial,因为我已经阅读了分布式SCM,这似乎是一种理想的情况.但是,我仍然更愿意将代码远程推送到Linux VPS,以防万一我的硬盘驱动器决定潜水.

So right now I'm learning Ruby on Rails, and I'm working through the book "Agile Web Development with Rails". I've also decided that I want to give Mercurial a go, because I've read up on distributed SCM's, and it seems like an ideal situation. I still, however, prefer to push my code remotely to my Linux VPS just incase my hard drive decides to take a dive.

因此,我的问题是针对Mercurial中的分支.现在,我已经建立了一个远程存储库,并且可以轻松地通过SSH推送更改(甚至我还建立了一个Nginx FastCGI站点也可以推送).但是,我想做的是为每章创建分支,以便在本书中保持整洁的历史记录.所以这就是我正在做的:

So, my question is specific to branching in Mercurial. Right now I've got a remote repository set up and I can push changes over SSH easily (hell I even set up an Nginx FastCGI site that lets me push, too). What I'd like to do, however, is create branches for each chapter as I work on them, so I can keep a nice organized history of my progress through the book. So this is what I'm doing:


$ hg branch chapter-10
(do chapter 10 stuff)
$ hg commit -m "Chapter 10 complete"
$ hg update default
$ hg merge chapter-10
$ hg commit -m "Merging chapter 10 into default"
$ hg push

一旦执行了push语句,我就会从Mercurial得到以下消息:

Once I execute the push statement, I get this message from Mercurial:


pushing to ssh://myserver/hg/depot
searching for changes
abort: push creates new remote branch 'chapter-10'!
(did you forget to merge? use push -f to force)

因此,在这一点上,我尝试再次执行hg merge,它告诉我没有要合并的内容,这显然是正确的,因为我只是合并了它.当我用-f强制推送时,一切似乎都很好,甚至Web界面也显示了适当的分支.

So at this point I try to do an hg merge again, and it tells me there's nothing to merge, which is obviously true because I just merged it. When I force the push with -f, everything seems fine, and even the web interface shows the appropriate branches.

总而言之,我的问题很简单:我这样做正确吗?使用Mercurial是否有更合适的方法(即"Mercurial方法")?老实说,我只希望存储库充当备份.我是分布式SCM模型的粉丝,但是对我来说,强迫推送有点肮脏".任何见解都将不胜感激!预先感谢.

To sum up, my question is simple: Am I doing this the right way? Is there a more appropriate way to do this with Mercurial (i.e. the "Mercurial way")? Honestly I just want the repository to serve as a backup. I'm a fan of the distributed SCM model, but to me it feels sorta "dirty" to force pushes. Any insight is greatly appreciated! Thanks in advance.

推荐答案

push -f是适合您的情况的选项,上个月进行了讨论,以在出现此"push creates new remote branch"警告时添加该命令. :请参见问题1513 .

The push -f is the right option for your case, and there was a discussion last month to add that command when this "push creates new remote branch" warning pops up: see issue 1513.

但是,第1974期(本月)提到了一些不受欢迎的问题效果(虽然不是您的情况).
参见此翻译的文章以了解更多信息在远程仓库上创建第二个头像.

However, issue 1974 (this month) mentions some undesirable effects (not in your case though).
See this translated article to know more about creating a second head on a remote repo.

更笼统地说,如果您并行编写章节,并且只想在特定(稳定)时间点合并它们,则可以使用分支

On the more general point, you can use branch if you are writing your chapter in parallel, and you want to merge them only at certain (stable) point in time

但是,如果您的书写过程更加线性,则可以只使用一个分支,并在此过程中放置​​一些标签.
但是,即使您已经放置了标签11和12,也应该回到第10章并添加一些行,这将使历史记录更难以阅读.因此,在这种情况下,分支仍然是一个好主意.

But if your writing process is more linear, you could use only one branch, and put some tags along the way.
However, should you go back to chapter 10 and add some lines, even though you already put tags 11 and 12, that would make the history harder to read. So branches are still a good idea in this case.

这篇关于与Mercurial SCM分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆