Mercurial Subrepos-您如何创建它们以及它们如何工作? [英] Mercurial Subrepos - How do you create them and how do they work?

查看:92
本文介绍了Mercurial Subrepos-您如何创建它们以及它们如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况

我有两个.NET解决方案(FooBar),以及一个包含ProjectA,ProjectB和ProjectC的公共库. FooBar引用了一个或多个库项目,但是这些库项目不在FooBar Solution文件夹中.

I have two .NET solutions (Foo and Bar) and a common library that contains ProjectA, ProjectB, and ProjectC. Foo and Bar reference one or more library projects, but the library projects are not located within the Foo and Bar Solution folders.

目录结构:

-- My Documents*
   -- Development
      -- Libraries
         -- ProjectA
         -- ProjectB
         -- ProjectC
   -- Projects
      -- Foo
         -- Solution
            -- .hg
            -- .hgignore
            -- Foo { Project Folder }
            -- FooTests { Project Folder }
            -- Foo.sln { References ProjectA }
            -- Foo.suo
      -- Bar
         -- Solution
            -- .hg
            -- .hgignore
            -- Bar { Project Folder }
            -- BarTests { Project Folder }
            -- Bar.sln { References ProjectA and ProjectB }
            -- Bar.suo

* alas,我仍在使用Windows XP ...

*alas, I'm still using Windows XP...

Mercurial子存储库

目标-我想设置子存​​储库,以便可以将任何引用的库项目的源代码存储在我的FooBar存储库中.

Goal - I want to set up subrepos so that I can store the source code for any referenced library projects in my Foo and Bar repositories.

根据此页面(实际上,这是我可以找到的唯一文档subrepos),设置子仓库需要在DOS控制台窗口中执行以下命令:

According to this page (which is literally the only documentation I can find on subrepos), setting up a subrepo requires executing the following commands from a DOS console window:

1| $ hg init main
2| $ cd main
3| $ hg init nested
4| $ echo test > nested/foo
5| $ hg -R nested add nested/foo
6| $ echo nested = nested > .hgsub
7| $ hg add .hgsub
8| $ ci -m "initial commit"

问题

  1. 是否可以从0.9.2版开始使用TortoiseHG执行任何或所有这些步骤?如果是,怎么办?我很确定1-3行可以,但是我不知道4-7行. TortoiseHG似乎没有任何记录.
  2. 以上代码的作用(逐行解释将不胜感激).以下是我在尝试解密时想到的一些具体问题:
    • >的作用是什么?我尝试在Mercurial文档中搜索>,但未找到任何内容.
    • 在第5行中,我不明白什么是nested/foo. foo是从哪里来的?什么是foo?仓库?文件夹?
    • 第6行-这个完全让我感到困惑.
    • 在第7行中,我假设将.hgsub添加到了main中?还是将其添加到nested?
  1. Can any or all of these steps be executed with TortoiseHG, as of version 0.9.2? If yes, how? I'm pretty sure lines 1-3 can, but I don't know about lines 4-7. None of this seems to be documented in TortoiseHG.
  2. What does the above code do (a line-by-line explanation would be much appreciated). Here are some specific questions that came to mind as I was trying to decipher it:
    • What does > do? I tried searching through the Mercurial docs for >, but didn't find anything.
    • In line 5, I don't understand what nested/foo is. Where did foo come from? What is foo? A repository? A folder?
    • Line 6 - this one completely baffles me.
    • In line 7, I assume .hgsub is being added to main? Or is it being added to nested?

更新

我添加了第8行代码:ci -m "initial commit".这有两件事:(1)将.hgsubstate文件添加到主仓库中,并且(2)将所有更改(包括新的子仓库)提交到主存储库中(消息为"initial commit"). .hgsubstate文件的目的是跟踪所有子存储库的状态,因此,如果您返回到较早的修订版,它还将从所有子存储库中获取正确的修订版.

I added an 8th line of code: ci -m "initial commit". This does two things: (1) adds a .hgsubstate file to the main repo and (2) commits all changes, including the new subrepo into the main repository (with message "initial commit"). The purpose of the .hgsubstate file is to keep track of the state of all subrepos, so if you return to an earlier revision, it will grab the correct revision from all subrepos as well.

更新2-一些说明

经过进一步的实验,我 我现在可以提供解决原始问题的步骤(主要使用Windows资源管理器和TortoiseHG):

After further experimentation, I think I can now provide the steps to solve my original problem (using mostly Windows Explorer and TortoiseHG):

创建子仓库

  1. Libraries/ProjectALibraries/ProjectB和主要存储库(Projects/Foo/SolutionProjects/Bar/Solution)必须是单独的存储库.
  2. 打开Projects/Foo/Solution.
  3. Libraries/ProjectA克隆到Projects/Foo/Solution.
  4. ProjectA添加到Foo存储库.
  5. 使用文本编辑器创建一个名为.hgsub的文件,其中包含以下内容:

  1. Libraries/ProjectA, Libraries/ProjectB, and the main repositories (Projects/Foo/Solution and Projects/Bar/Solution) must be separate repositories.
  2. Open Projects/Foo/Solution.
  3. Clone from Libraries/ProjectA to Projects/Foo/Solution.
  4. Add ProjectA to the Foo repository.
  5. Use a text editor to create a file called .hgsub, containing the following:

ProjectA = ProjectA

  • 打开DOS控制台窗口,然后输入以下命令(请参见下面的注释):

    cd c:\...\Projects\Foo\Solution
    hg ci -m "Committing subrepo "ProjectA"
    

  • 对于Bar,步骤基本相同,只是.hgsub文件应包含两个项目的条目,如下所示:

  • For Bar, the steps are basically the same, except the .hgsub file should contain entries for both projects, like this:

    ProjectA = ProjectA  
    ProjectB = ProjectB
    

  • 注意:从TortoiseHG 0.10(计划于3月开始)开始,您将能够使用HG Commit shell命令来执行此操作,但是现在,您必须使用该命令线.

    Note: starting with TortoiseHG 0.10 (which is slated for March), you will be able to use the HG Commit shell command to do this, but for now, you have to use the command line.

    所有这些设置完成后,它会变得容易一些.

    Once this is all set up, it gets a little easier.

    提交更改-要提交对FooBar的更改,请对每个子存储库执行Synchronize/Pull操作,以使子存储库与库项目存储库中的最新修订同步.然后,您再次使用命令行来提交更改(直到版本0.10时才可以使用TortoiseHG提交).

    Committing changes - to commit changes to Foo or Bar, you do a Synchronize/Pull operation for each subrepo to get the subrepos in sync with the latest revisions in the library project repositories. Then you again use the command line to commit the changes (until version 0.10, when you can just use TortoiseHG to commit).

    将工作目录更新到较早的版本-这似乎与TortoiseHG正常工作,并且似乎不需要使用任何DOS命令.要在Visual Studio中实际使用早期版本,您需要执行Synchronize/Push操作,将旧版本的库项目放回Libraries/ProjectX文件夹中.

    Updating working directory to an earlier revision - This seems to work pretty normally with TortoiseHG and doesn't seem to require use of any DOS commands. To actually work with the earlier revision in Visual Studio, you will need to do a Synchronize/Push operation to put the older version of the library projects back into the Libraries/ProjectX folder.

    尽管我喜欢TortoiseHG来完成简单的任务,但最好为经常使用的子仓库操作(尤其是更新)编写批处理文件.

    As much as I like TortoiseHG for simple tasks, it's probably better to write batch files for frequently used subrepo operations (especially updating).

    希望这对以后的人有所帮助.如果您发现任何错误,请告诉我(或者,如果可以的话,请随时进行编辑).

    Hope this helps someone in the future. If you see any mistakes, please let me know (or feel free to edit yourself if you are able).

    推荐答案

    您可能可以尝试一下这些东西,并且比编写问题所花的时间更快地学习它,但我会咬一口.

    You could probably try this stuff out and learn it more quickly than writing up your question took, but I'll bite.

    这些步骤中的任何一个或全部可以是 从TortoiseHG开始执行,自 版本0.9.2?如果是,怎么办?

    Can any or all of these steps be executed with TortoiseHG, as of version 0.9.2? If yes, how?

    TortiseHG尚未将GUI包装器放在子存储库创建周围,但是TortiseHG一直在使用命令行方面做得很好.使用命令行来创建它们,然后您就可以开始使用它们了.

    TortiseHG doesn't yet put GUI wrappers around sub-repo creation, but TortiseHG has always done a great job of working with the command line. Use the command line to create and them and you're good to go.

    是什么 上面的代码做(一行一行 解释会很多 感激).

    What does the above code do (a line-by-line explanation would be much appreciated).

    hg init main  # creates the main repo
    cd main # enter the main repo
    hg init nested # create the nested. internal repo
    echo test > nested/foo # put the word test into the file foo in the nested repo
    hg -R nested add nested/foo # do an add in the nested repo of file foo
    echo nested = nested > .hgsub # put the string "nested = nested" into a file (in main) named .hgsub
    hg add .hgsub # add the file .hgsub into the main repo
    

    这里有一些具体的 我当时想到的问题 试图破译它:>做什么?

    Here are some specific questions that came to mind as I was trying to decipher it: What does > do?

    这与标准外壳程序(unix和dos)无关,用于将结果放入名为X的文件中"

    That has nothing to do with mercurial it's standard shell (unix and dos) for "put the result into a file named X"

    在第5行中,我没有 了解嵌套/foo是什么.在哪里 foo是从哪里来的?什么是foo?一种 仓库?一个文件夹?

    In line 5, I don't understand what nested/foo is. Where did foo come from? What is foo? A repository? A folder?

    这是子仓库中的文件. Foo是传统的任意名称,任意内容都是字符串"test"

    It's a file in the subrepo. Foo is a traditional arbitrary name, and the arbitrary contents are the string "test"

    第6行-此 一个完全让我感到困惑.

    Line 6 - this one completely baffles me.

    它会将内容放入.hgsub中,以表明nested是名为nested并位于nested的嵌套回购.

    It's putting the contents in .hgsub necessary to say that nested is a nested repo named nested and located at nested.

    第7行 我假设.hgsub被添加到 主要的?还是要添加到嵌套中?

    In line 7, I assume .hgsub is being added to main? Or is it being added to nested?

    主要

    假设我设置了我的子仓库, 现在我的Bar资料库已完成 修订版10.如果我尝试更新到 修订版7,这是否会导致我的图书馆 文件夹(我的 文件/开发/图书馆/ProjectA 和.../Libraries/ProjectB)更新 到版本7中存储的任何内容 出色地?鉴于Foo也指 图书馆/ProjectA,可能会得到 有趣!

    Let's say I get my subrepos set up, and my Bar repository is now up to revision 10. If I attempt to update to revision 7, will this cause my library folders (My Documents/Development/Libraries/ProjectA and .../Libraries/ProjectB) to update to whatever is stored in revision 7 as well? Given that Foo also refers to Libraries/ProjectA, this could get interesting!

    修订号不会保留,但是您可以通过编辑.hgsubstate文件来控制.

    Revision numbers won't carry across, but you have control by editing the .hgsubstate file.

    这篇关于Mercurial Subrepos-您如何创建它们以及它们如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆