使用 Mercurial SCM 进行分支
现在我正在学习 Ruby on Rails,并且正在阅读《Agile Web Development with Rails》一书。我还决定尝试一下 Mercurial,因为我已经阅读了分布式 SCM 的相关内容,而且这似乎是一个理想的情况。然而,我仍然更喜欢将代码远程推送到我的 Linux VPS,以防我的硬盘驱动器崩溃。
所以,我的问题是针对 Mercurial 中的分支的。现在我已经设置了一个远程存储库,我可以轻松地通过 SSH 推送更改(我什至设置了一个 Nginx FastCGI 站点,也可以让我推送)。然而,我想做的是在我处理每一章时为它们创建分支,这样我就可以通过这本书保留一个井井有条的进展历史。这就是我正在做的事情:
$ 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收到这条消息:
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 界面也显示了适当的分支。
总而言之,我的问题很简单:我这样做的方法正确吗?是否有更合适的方式来使用 Mercurial 来做到这一点(即“Mercurial 方式”)?老实说,我只是希望存储库作为备份。我是分布式 SCM 模型的粉丝,但对我来说,强制推送感觉有点“肮脏”。任何见解都将不胜感激!提前致谢。
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.
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
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)
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
push -f
是适合您情况的正确选项,上个月有一次讨论,当弹出此“push Creates new Remote Branch
”警告时添加该命令:请参阅问题 1513。然而,issue 1974(本月)提到了一些不良影响(不是不过就你的情况而言)。
请参阅此翻译文章了解更多信息在远程存储库上创建第二个头。
更一般地说,如果您并行编写章节,并且您只想在某个(稳定)时间点合并它们,则可以使用分支
但是如果您的编写过程更加线性,则可以仅使用一个分支,并沿途放置一些标签。
然而,如果您返回第 10 章并添加一些行,即使您已经放置了标签 11 和 12,这也会使历史记录变得更难阅读。所以在这种情况下分支仍然是一个好主意。
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.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
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.
我不知道你的具体问题,但从你的评论来看,你似乎使用了你可能想使用标签的分支。
当多人在同一个项目上合作并且您想要创建工作分离时,通常会使用分支,以便一个人可以处理稳定的代码,而另一个人可以做一些暂时破坏功能的实验性工作。或者,分支用于稳定发布,而开发则在主干中进行。
标签(或标签)主要用于创建一个标记,表示对代码版本的重要性。例如,如果您想标记第 10 章的完成,只需使用“chapter-10”标签标记所有当前版本即可。无需分支。如果出于某种原因有必要,您可以在将来的任何时候从标记版本分支。
I don't know about your specific problem, but from your comments it seems that you use branches where you probably wanted to use tags.
Branches are generally used when multiple people cooperate on the same project and you want to create a work separation so one person can work on a stable piece of code, while the other does something experimental that temporarily breaks functionality. Alternatively branches are used to stabilize for release, while development is going on in trunk.
Tags (or labels) are used to primarily create a marker signifying some importance to the version of code. Like for example if you want to mark a completion of chapter 10, you just tag all current versions with a 'chapter-10' tag. There is no need to branch. You can branch from a tagged version at any point in future if it would be necessary for some reason.
In this case I feel that it's totally ok to use -f for the push.它只是创建新的分支,而不是头。创建远程头完全是另一回事。
In this case I feel that it's totally ok to use -f for the push. It just creates new branches, not heads. Creating remote heads is another matter entirely.