简体   繁体   English

如何在 mercurial 中交换我的主存储库位置

[英]How do I swap my master repository location in mercurial

I have a local mercurial repository.我有一个本地 mercurial 存储库。 And I back it up with a clone in a separate folder that lives in my google drive folder.我在位于我的谷歌驱动器文件夹中的单独文件夹中使用克隆备份它。 Every now and again I'll go into the google drive repo and do an hg pull, and google drive takes care of backing it up.我会时不时地进入 google drive repo 并执行 hg pull,google drive 负责备份它。 But I'd like to swap those responsibilities, so that my local is a clone of the one in google drive.但我想交换这些职责,以便我的本地是谷歌驱动器中的一个的克隆。 In other words, today I do this:换句话说,今天我这样做:

From my local c:\\source folder:从我的本地 c:\\source 文件夹:

  1. do stuff做东西
  2. hg commit汞提交
  3. cd c:\\googledrive\\source cd c:\\googledrive\\source
  4. hg pull汞拉

I would rather:我宁愿:

From my local c:\\source folder:从我的本地 c:\\source 文件夹:

  1. do stuff做东西
  2. hg commit汞提交
  3. hg push汞推

I don't know what to do in my hgrc files to make that happen.我不知道在我的 hgrc 文件中该怎么做才能做到这一点。 Can someone help?有人可以帮忙吗? Here's the contents of my c:\\source hgrc:这是我的 c:\\source hgrc 的内容:

# Generated by TortoiseHg settings dialog

[tortoisehg]
summarylen = 80
engmsg = True
editor = notepad
tabwidth = 2
forcerepotab = False
monitorrepo = localonly

[ui]
username = *****

And this is the contents of the clone in google drive这是谷歌驱动器中克隆的内容

[paths]
default = c:\source\SwissArmyKnife

Your question reveals an illuminating misconception.你的问题揭示了一个有启发性的误解。 When one says that Mercurial is a Distributed Version Control System (DVCS), it means that there is no 'master' repository.当有人说 Mercurial 是分布式版本控制系统 (DVCS) 时,这意味着没有“主”存储库。

When you type hg push <repo> or hg pull <repo> , then Mercurial compares the changesets in the current repository with those in <repo> , and pushes or pulls changesets to make this one and the remote one consistent.当您键入hg push <repo>hg pull <repo> ,Mercurial 会将当前存储库中的变更集与<repo>的变更集进行比较,并推送或拉取变更集以使该变更集与远程变更集一致。 The <repo> can be indicated by a URL (that is, ssh://... , or http://... ) or else by a shorthand named in your .hg/hgrc : thus in your case you might add <repo>可以由 URL(即ssh://...http://... )或在您的.hg/hgrc命名的速记.hg/hgrc :因此在您的情况下,您可能添加

[paths]
gdrive = c:\googledrive\source

and that would mean that you could write hg push gdrive or hg pull gdrive and Mercurial would know what you meant.这意味着您可以编写hg push gdrivehg pull gdrive并且 Mercurial 会知道您的意思。 You can have multiple paths listed here.您可以在此处列出多个路径。

There's one 'magic' path, however.然而,有一条“神奇”的道路。 If you have a path default then that's the path that Mercurial uses if you don't specify a <repo> .如果您有一个default路径,那么如果您没有指定<repo> ,这就是 Mercurial 使用的路径。

Thus (finally), if you adjust the .hg/hgrc in your c:\\source folder to include因此(最后),如果您调整c:\\source folder.hg/hgrc以包含

[paths]
default = c:\googledrive\source

then in that directory plain hg push will sync changesets with that drive.然后在该目录中,plain hg push将与该驱动器同步变更集。

When you clone a repository ( hg clone ) Mercurial generally adds to your .hg/hgrc a default = ... which indicates the location from which you cloned the repository.当您克隆存储库 ( hg clone ) 时,Mercurial 通常会在您的.hg/hgrc一个default = ... ,表示您从中克隆存储库的位置。 Given that default behaviour, it's very natural to think of that repository as the 'master' one, but there's nothing fundamentally special about it.鉴于这种默认行为,很自然地将该存储库视为“主”存储库,但从根本上说,它没有什么特别之处。

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

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