Mercurial 新手:两个预先存在的代码库可以同步吗?

发布于 2025-01-02 14:49:09 字数 570 浏览 0 评论 0原文

最近,我开始通过将所有文件复制到新目录来开发项目的“便携式”版本。可移植目录与稳定目录的不同之处仅在于删除或注释掉了哪些内容;没有添加任何内容。

我终于决定是时候学习源代码控制了。每个人都说简单的开始比其他任何事情都更重要,我最终选择了 Mercurial,因为它有利于分支,并且(更重要的是)我喜欢我在网上找到的教程(例如,http://hginit.comhttp://hgbook.red-bean .com/)。

我为我的稳定目录创建了一个存储库,并在中央存储库 (Dropbox) 中创建了一个克隆。我正在提交、推送等。但是现在,我想将我的(已经存在的)可移植目录与中央存储库链接起来。比如说,我希望能够修复稳定代码中的错误,将其推送到中央存储库,然后将错误修复拉入可移植版本中,而无需更改可移植代码中的其他任何内容。

我不确定首先要使用可移植代码做什么。如果我将中央存储库克隆到可移植目录,那么第一次更新可移植目录时,我的所有可移植代码是否都会被覆盖?

Recently I started working on a "portable" version of a project by copying all the files to a new directory. The portable directory differs from the stable directory only in terms of what has been deleted or commented out; nothing has been added.

I finally decided it's time to learn source control. Everyone says simply starting is more important than anything else, and I ultimately chose Mercurial since it's good for branching and (more importantly) I liked the tutorials I found online (e.g., http://hginit.com and http://hgbook.red-bean.com/).

I made a repository for my stable directory, and a clone in a central repository (Dropbox). I'm committing, pushing, etc. Now, however, I'd like to link my (already existing) portable directory with the central repository. I'd like to be able to, say, fix a bug in my stable code, push it to the central repo, and then pull the bug fix into the portable version--without changing anything else in the portable code.

I'm unsure what to do first with the portable code. If I clone the central repo to the portable directory, won't all my portable code be overwritten the first time I update the portable directory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

﹏雨一样淡蓝的深情 2025-01-09 14:49:09

您需要将“中央”存储库克隆到您的可移植目录,然后才能执行您所描述的任何工作。但是,一个简单的解决方法是将可移植目录复制到其他位置并创建一个新的空文件夹。然后,将您的存储库克隆到该目录中。之后,您应该能够将以前的可移植目录复制并粘贴到克隆版本中,并允许它覆盖那里的文件。这将允许您将这些更改提交到版本控制中并与中央存储库同步。

如果此方法不起作用,您仍然需要克隆中央存储库,然后手动将现有可移植位置的所有“待处理”更改更改为新的克隆版本。

You will need to clone the "central" repository to your portable directory before you will be able to do any work like you describe. However, an easy fix is to copy you portable directory somewhere else and create a new, empty folder. Then, clone your repository into that directory. After that, you should be able to just copy and paste your previous portable directory into the cloned version and allow it to overwrite the files there. That will allow you to commit those changes into version control and be in sync with the central repository.

If this method won't work, you will still have to clone the central repository and then make all of your "pending" changes to the existing portable location by hand to your new cloned version.

闻呓 2025-01-09 14:49:09

听起来便携式版本应该是您的稳定存储库中的一个分支。由于您已经拥有不在存储库中的现有版本,我认为最简单的方法是使用 addremove 命令。

我要做的就是首先确保您的稳定分支最近发生了任何更改,并确保您在某处拥有存储库的备份副本,以防出现任何问题。然后,我会删除稳定存储库目录中的所有内容,除了 .hg 目录和任何其他存储库管理文件,例如 .hgignore.hgsub.hgeol 等。然后我会将便携式版本复制到该目录中并运行 hg addremoveaddremove 命令将自动添加所有新文件并删除所有丢失的文件(在本例中应该只是删除)。现在,我将使用 hgbranch 将其标记为单独的分支,其中 是您想要命名可移植分支的任何名称。然后像往常一样hg commit

现在您已经有了稳定分支(称为“默认”分支,除非您已重命名)和新的可移植分支。现在,当您对稳定分支进行更改时,您可以hg update到您的可移植分支并运行hg merge default(或用稳定分支的名称替换默认值)来合并这些更改进入便携式分支。

It sounds like the portable version should be a branch in your stable repo. Since you've already got an existing version that isn't in the repository I think the easiset way to do this is with the addremove command.

What I would do is first make sure any recent changes to your stable branch and make sure you've got a backup copy of your repo somewhere in case anything goes wrong. Then I would delete everything from your stable repository directory except for the .hg directory and any other repository management files such as .hgignore, .hgsub, .hgeol, etc. Then I would copy the portable version into that directory and run hg addremove. The addremove command will automatically add all new files and remove all missing files (which should be just removes in this case). Now I would mark this as a separate branch with hg branch <branch_name> where <branch_name> is whatever you want to name your portable branch. Then just hg commit as usual.

Now you've got your stable branch (called 'default' unless you've renamed it) and your new portable branch. Now when you make changes to the stable branch you can hg update to your portable branch and run hg merge default (or replace default with your stable branch's name) to merge those changes into the portable branch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文