通过 USB 闪存驱动器使用 Mercurial
简而言之:
如何使用 Hg 使用闪存驱动器作为中介来同步两台计算机之间的存储库?
更多详细信息:
我经常在没有以任何方式联网的计算机上开发代码,并使用 USB 闪存驱动器在这些计算机之间传输文件。现在我想在每台机器上使用 Hg 存储库在这些机器上开发一些软件,我可以使用闪存驱动器传输机制经常同步这些软件。
我对 Hg 有点熟悉,因为我以最简单的方式使用它,仅在独立机器上对我自己的工作进行版本控制,但不确定我到底应该做什么来使用它来使用闪存同步两台计算机之间的存储库开车作为中介。例如,也许我需要在闪存驱动器上创建一个临时存储库(使用“克隆”),然后从中同步到(使用“推”和“拉”),并通过 A→flash、flash→B 执行此操作,B→闪光,闪光→A?您对操作和命令顺序的回答越具体,对我来说就越有用。
最后,我如何开始这个过程?我是否需要做一些事情以便 Hg 知道这些都是同一个代码库的一部分?例如,我当前在不同计算机上的每个存储库都是在我开始使用 Hg 之前独立创建的,尽管所有代码都很相似,但每个存储库都进行了独立的更改,并且存储库彼此一无所知。如果我需要做的事情与我在统一所有内容后需要做的事情不同,那么为我详细说明这个过程也会有所帮助。
如果重要的话,这些机器可以运行任何 Windows、Mac 或 Linux,并且我的 Mercurial 版本在每台机器上都略有不同(尽管如果需要,Mercurial 版本可以统一)。
In short:
How can I use Hg to synchronize repositories between two computers using a flash drive as intermediary?
With more detail:
I often develop code on computers that aren't networked in any way, and I transfer files between these machines using a USB flash drive. Now I would like to develop some software across these machines using Hg repositories on each machine that I can frequently sync-up using the flash drive transfer mechanism.
I'm slightly familiar with Hg, as I use it in the most simple way possible for versioning only my own work on independent machines, but am uncertain as to exactly what I should do to use it to synchronize repositories between two computers using a flash drive as intermediary. Maybe, for example, I need to create a temporary repository on the flash drive (using “clone”) from which I then sync to (using “push” and “pull”), and do this by A→flash, flash→B, B→flash, flash→A? The more specificity in your answer regarding the sequence of actions and commands, the more useful to me.
Finally, how do I get this process started? Do I need to do something so Hg knows these are all part of one code base? For example, each of my current repositories on the different computers was created independently from a time before I started using Hg, and although all the code is similar, independent changes have been made to each, and the repositories know nothing about each other. If what I need to do with this is different than what I need to do for the ongoing case once I have everything unified, spelling this process out for me as well would also help.
In case it's important, these machines can be running any of Windows, Mac, or Linux, and my versions of Mercurial are slightly different on each machine (though the Mercurial versions could be unified if needed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面关于使用闪存驱动器作为中间存储位置的描述应该可行。我的流程是:
初始设置
将存储库从计算机 A 克隆到闪存驱动器
hg clone C:/path/to/repo/AX:/path/to/flash/drive/repo
将存储库从闪存驱动器克隆到计算机 B
hg clone X:/path/to/flash/drive/repo C:/path/to/repo/B
工作流程
从计算机 A 到闪存驱动器
hg push X:/path/to/flash/drive/repo
从闪存驱动器拉到计算机 B
hg pull X:/path/to/flash/drive/repo
在计算机 B 上编辑/提交存储库
Mercurial 通过查看每个存储库中提交的 SHA1 哈希键来了解两个任意存储库是否具有共同的祖先。换句话说,假设两个存储库在其历史记录中至少有一个公共哈希键,Mercurial 将尝试合并它们。在您的具体情况下,两个存储库最初都没有版本控制,Mercurial 将需要一些帮助。最好的办法是到达两个存储库相同的地方,然后执行
hg init
。 Mercurial 应该从此时开始处理共享。What you have described above in terms of using the flash drive as an intermediate storage location should work. My process would be:
initial setup
clone the repo from computer A to flash drive
hg clone C:/path/to/repo/A X:/path/to/flash/drive/repo
clone the repo from flash drive to computer B
hg clone X:/path/to/flash/drive/repo C:/path/to/repo/B
working process
push from computer A to flash drive
hg push X:/path/to/flash/drive/repo
pull from flash drive to computer B
hg pull X:/path/to/flash/drive/repo
edit/commit repo on computer B
Mercurial knows if two arbitrary repositories have a common ancestor by looking at the SHA1 hash keys of the commits in each repo. In other words, assuming both repos have at least one common hash key in their histories, Mercurial will attempt to merge them. In your specific case, where both repos are initially un-versioned, Mercurial will need some help. The best thing to do would be to get to a place where both repos are identical and then perform your
hg init
. Mercurial should handle sharing from this point on.在不同机器上离线工作时。最好使用Mercurial自带的bundle命令。因此呼应 dls 所写的内容,但过程略有变化。
dls 提到的初始设置。
或
hg bundle --base null ../project.hg
project.hg
文件复制到您的另一台计算机hg init
hg pull
hg update
hg log
,两个存储库将显示相同的基本修订版和提示使用捆绑包的工作流程
我使用略有不同的工作流程。我将这些存储库保留为不同的存储库。
我将它们称为 repo1 和 repo2。
假设repo1当前的tip是4f45839f613c。
命令:该包包含自指定基本版本以来的所有更改。
命令:
如果捆绑包包含 repo2 中已存在的更改,则在拉取时将忽略这些更改。只要捆绑包不会变得很大,就可以一次又一次地使用带有相同 --base 修订版的捆绑命令来创建包含进一步更改的捆绑包。
关于捆绑包:这些捆绑包(非常好)被压缩。
创建存储库的(压缩)备份
[编辑:添加有关此主题的一些链接]
[编辑:我认为是优势使用捆绑包]
捆绑包可以离线创建、复制或通过邮件发送。使用推送到闪存驱动器上的存储库需要连接它。捆绑包更容易,因为它并不要求您从中推送和拉取的两个存储库必须同时可用。
除此之外,捆绑包还可以有两种类型:变更集和增量。变更集捆绑包是完整的独立捆绑包。您还可以使用捆绑包作为单个文件进行备份。
When working offline on different machines. It is better to use the bundle command that comes with Mercurial. So echoing what dls wrote but a slight change process.
Initial setup as mentioned by dls.
or
hg bundle --base null ../project.hg
project.hg
file to your other computerhg init
hg pull <path/project.hg>
hg update
hg log
, both the repository will show same base revisions and tipWorkflow using bundle
I use a slightly different workflow. I keep these repositories as distinct repositories.
I mention them as repo1 and repo2.
Suppose that the current tip of repo1 is 4f45839f613c.
Command : This bundle contains all changes since the specified base version.
Command :
If the bundle contains changes that are already present in repo2, then these will be ignored when pulling. As long as the bundle doesn't grow to large, this allows to use the bundle command with the same --base revision again and again to create bundles including further changes.
About bundles: these are (very well) compressed.
creates a (compressed) backup of the repository
[Edit : Adding some links on this topic]
[Edit: What I think is advantage of using bundle]
Bundles can be created offline, copied or sent via mail. Using push to repo on flash drive, requires it to be connected. Bundles are easier since it does not maintain that the two repo from which you push and pull have to be available at the same time.
Apart from that, bundles can also be of two types : Changesets and Incremental. Changeset bundles are complete standalone bundles. You can also use bundles for backup as a single file.