简体   繁体   English

`hg pull --rebase`类似于`svn update`吗?

[英]Is `hg pull --rebase` analogous to `svn update`?

This question assumes there's a "blessed" central repository that members of a team 这个问题假定团队成员有一个“有福的”中央存储库

  1. clone from 克隆自
  2. push to when they have contributions that they want other team members to see 当他们有他们希望其他团队成员看到的贡献时,推动他们
  3. pull from when they want to see other people's contributions. 当他们想要看到其他人的贡献时拉出来。
  4. etc. 等等

If so, I would assume hg update is not analogous to svn update (why would there be two commands that do exactly the same thing?). 如果是这样,我会认为hg updatesvn update不相似(为什么会有两个命令完全相同?)。 From what I can gather, hg update more like svn revert . 从我可以收集到的, hg update更像svn revert Is that correct? 那是对的吗?

Update: 更新:

My understanding of rebase is largely based on the "A common case" section on this page: 我对rebase的理解主要基于本页的“常见案例”部分:
https://www.mercurial-scm.org/wiki/RebaseProject https://www.mercurial-scm.org/wiki/RebaseProject

As others have indicated, almost but not quite. 正如其他人所指出的,差不多但并不完全。 In order of decreasing similarity to svn update (and increasing compliance with general DVCS, and specifically Mercurial, best practices[1]): 为了减少与svn update相似性(并且增加对一般DVCS的遵从性,特别是Mercurial,最佳实践[1]):

  1. hg pull -u (or hg pull followed by hg update ) with your changes uncommitted and no committed changes since your last pull. hg pull -u (或hg pull然后是hg update ),您的更改未提交,并且自上次提取后没有提交更改。 This is as close to svn update as you can get, but is pretty bad DVCS practice. 这与你可以得到的svn update接近,但DVCS的做法非常糟糕。 One of the niceties of DVCS is that you can commit your changes before trying to merge them with others, and thus have a backup version to rollback and retry a failed merge, and this practice gives that up. DVCS的一个细节是你可以在尝试将它们与其他人合并之前提交你的更改,从而有一个备份版本来回滚并重试失败的合并,这种做法就是这样。 Don't do it. 不要这样做。

  2. hg pull --rebase after committing your changes. 提交更改后的hg pull --rebase This pulls the upstream changes, re-applies your changes on top of them, and lets you push your changes back as a linear history. 这会拉动上游更改,在其上重新应用更改,并允许您将更改作为线性历史记录推回。 The end result will look very similar to a Subversion revision history, but you get the DVCS benefit of committing before merging. 最终结果看起来与Subversion修订历史非常相似,但您可以在合并之前获得DVCS提交的好处。 I do not know how the safety of this mode of operation compares between Mercurial and Git, though; 我不知道这种操作模式的安全性如何在Mercurial和Git之间进行比较; in Git, pre-rebase versions of your changes will still be there until you do a git gc , but Mercurial doesn't have an explicit gc safety net. 在Git中,你的更改的pre-rebase版本仍然存在,直到你执行git gc ,但Mercurial没有明确的gc安全网。

  3. hg pull followed by hg merge with your changes already committed to your local copy. hg pull后跟hg merge你已经提交到本地副本的更改。 This is the traditional Mercurial practice for doing the functional analog of svn update , notwithstanding footnote 1 below. 这是执行svn update功能模拟的传统Mercurial实践,尽管下面的脚注1。 This results in a nonlinear version history, but all changes are tracked and inspectable. 这会产生非线性版本历史记录,但会跟踪和检查所有更改。

That said, there is much wisdom in thinking of Mercurial (and other DVCSes) on their own terms, and not trying to translate from Subversion/CVS-style thinking. 也就是说,以自己的方式思考Mercurial(以及其他DVCS)并没有尝试从Subversion / CVS风格的思维转换。

  1. If you are not of the rewrite-history-to-keep-it-linear school of thought. 如果你不是重写 - 历史 - 保持线性的思想学派。 If you are, then rebase is probably preferable to update . 如果你是,那么rebase可能更适合update The Mercurial community tends to favor update . Mercurial社区倾向于支持update

Not exactly. 不完全是。

hg pull grabs the revisions from the other repository and adds them to the locally available revisions in your clone of the repository, but does not update your working copy - only your repository (which, for DCVS like hg/git/etc is not the same thing as a working copy). hg pull从其他存储库中获取修订版并将它们添加到存储库克隆中的本地可用修订版,但不更新您的工作副本 - 仅更新您存储库 (对于DCVS,如hg / git / etc不同)作为工作副本的事情)。

hg update updates your actual working copy to the latest revision in your local repository. hg update将您的实际工作副本更新到本地存储库中的最新版本。

This differs from Subversion because in svn, there is no such thing as your "local repository" - the only repository is the one on the server; 这与Subversion不同,因为在svn中,没有“本地存储库”这样的东西 - 唯一的存储库是服务器上的存储库; you only have a working copy locally. 你只在本地有一份工作副本。 Hence why update is only a single command, as opposed to Mercurial's pull and then update . 因此,为什么update只是一个命令,而不是Mercurial的pull然后update

The equivalent to svn update for Mercurial would be hg pull --update , which is equivalent to doing hg pull and then hg update one after another. 相当于Mercurial的svn update将是hg pull --update ,这相当于做hg pull然后hg update一个接一个地hg update

An end-to-end workflow for DCVS with a "central" repo looks something like this: 具有“中央”仓库的DCVS的端到端工作流程如下所示:

  1. A does hg commit on some changes. A会对某些更改进行hg commit
  2. A does hg push to push them the central repository. A hg push将它们推向中央存储库。
  3. B does hg pull to pull them from the central repository into their own clone. B则hg pull从中央存储库将他们拉进自己的克隆。
  4. B does hg update to update their working copy to reflect the changes pulled into their clone. B执行hg update以更新其工作副本以反映拉入其克隆的更改。

In systems without a central repo, it would instead look something like this: 在没有中央存储库的系统中,它看起来像这样:

  1. A does hg commit on some changes. A会对某些更改进行hg commit
  2. B, who has cloned A's repo, wants those changes, and thus does an hg pull directly from A's repo. 已经克隆了A的回购的B,想要那些改变,因此直接从A的回购中获取hg pull
  3. B uses hg update to update their working copy to the changes. B使用hg update将其工作副本hg update为更改。

Also, the equivalent to svn revert is hg revert . 此外,相当于svn reverthg revert :) :)

hg pull --update

would be an equivalent of svn update 将等同于svn update

As described in this SO question 如本SO问题所述

The hg command push and pull move changes between repositories and update and commit moves changes between your working copy and your local repository. hg命令pushpull在存储库之间进行更改,并且updatecommit会在工作副本和本地存储库之间移动更改。

So in a DVCS, you have 2 notions instead of one: 所以在DVCS中,你有2个概念而不是1个概念:

  • local repo (pull/push) 本地回购(拉/推)
  • working directory (which is the only local representation of the "tip" of a repo with SVN) 工作目录(这是SVN回购“尖端”的唯一本地表示)

Here's a great beginners guide to mercurial http://hginit.com/ . 这是mercurial http://hginit.com/的优秀初学者指南。 Should explain most things clearly. 应该清楚解释大部分事情。 Starting off with "Do not try and apply svn knowledge to distributed vcs's"! 从“不要尝试将svn知识应用于分布式vcs”开始!

The command hg pull --rebase isn't exactly analogous to svn update , but the result can be the same. 命令hg pull --rebase并不完全类似于 svn update ,但结果可能是相同的。

In Subversion, if you update your working copy you get the latest changes in the repository merged in with any local changes. 在Subversion中,如果更新工作副本,则会获得与任何本地更改合并的存储库中的最新更改。 So the files in your repository are up to date but you might still have uncommitted changes. 因此,存储库中的文件是最新的,但您可能仍然有未提交的更改。

In Mercurial, hg pull --rebase , will get the latest changes from the 'central repository' (or whatever repository you're pulling from) to update your repository then shuffle along your local commits. 在Mercurial中, hg pull --rebase将从“中央存储库”(或您正在提取的任何存储库)获取最新更改,以更新您的存储库,然后随机提交您的本地提交。 You'll still need an hg update to make your working copy the same as your local repository. 您仍然需要hg update以使您的工作副本与本地存储库相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM