Mercurial Subrepos,如何控制我想将哪个变更集用于子存储库?

发布于 2024-09-02 06:59:21 字数 1816 浏览 5 评论 0原文

我正在阅读子存储库,并在本地运行了一些测试,到目前为止似乎工作正常,但我有一个问题。

如何指定/控制要用于特定子存储库的变更集?

例如,假设我有以下两个项目:

class library                    application
o    fourth commit               o   second commit, added a feature
|                                |
o    third commit                o   initial commit
| 
| o  second commit
|/
o    initial commit

现在,我希望类库作为我的应用程序的子存储库,但由于最长的分支(最终作为第四次提交的分支)的不成熟,我想暂时使用“第二次提交”提示。

假设有可能的话,我该如何配置呢?

这是一个批处理文件,用于设置上述两个存储库+将库添加为子存储库。

如果运行批处理文件,它将输出:

[C:\Temp] :test
...
v4

正如您从最后一行看到的,它验证类库中文件的内容,即第四次提交的“v4”。我希望它是“v2”,并保留为“v2”,直到我准备好从类库存储库中获取更新版本。

谁能告诉我是否可以做我想做的事情,如果可以,我需要做什么才能将我的子存储库锁定到正确的变更集?

批处理文件:

@echo off
if exist app rd /s /q app
if exist lib rd /s /q lib
if exist app-clone rd /s /q app-clone


rem == app ==
hg init app
cd app
echo program>main.txt
hg add main.txt
hg commit -m "initial commit"
echo program+feature1>main.txt
hg commit -m "second commit, added a feature"
cd ..

rem == lib ==
hg init lib
cd lib
echo v1>lib.txt
hg add lib.txt
hg commit -m "initial commit"
echo v2>lib.txt
hg commit -m "second commit"
hg update 0
echo v3>lib.txt
hg commit -m "third commit"
echo v4>lib.txt
hg commit -m "fourth commit"
cd ..

rem == subrepos ==
cd app
hg clone ..\lib lib
echo lib = ..\lib >.hgsub
hg add .hgsub
hg commit -m "added subrepo"
cd ..

rem == clone ==
hg clone app app-clone

type app-clone\lib\lib.txt

编辑:好的,我得到了答案,谢谢@VonC,我添加了将以下部分添加到我的批处理文件中,位于 rem == clone == 行上方,并重新执行它,现在它将子存储库锁定到正确的变更集。

rem == lock ==
cd app\lib
hg update 1
cd ..
hg commit -m "lock to second commit"
cd ..

I am reading up on subrepos, and have been running some tests locally, seems to work OK so far, but I have one question.

How do I specify/control which changeset I want to use for a particular subrepo?

For instance, let's say I have the following two projects:

class library                    application
o    fourth commit               o   second commit, added a feature
|                                |
o    third commit                o   initial commit
| 
| o  second commit
|/
o    initial commit

Now, I want the class library as a subrepo of my application, but due to the immaturity of the longest branch (the one ending up as fourth commit), I want to temporarily use the "second commit" tip.

How do I go about configuring that, assuming it is even possible?

Here's a batch file that sets up the above two repos + adds the library as a subrepo.

If you run the batch file, it will output:

[C:\Temp] :test
...
v4

As you can see from that last line there, it verifies the contents of the file in the class library, which is "v4" from the fourth commit. I'd like it to be "v2", and persist as "v2" until I'm ready to pull down a newer version from the class library repository.

Can anyone tell me if it is possible to do what I want, and if so, what I need to do in order to lock my subrepo to the right changeset?

Batch-file:

@echo off
if exist app rd /s /q app
if exist lib rd /s /q lib
if exist app-clone rd /s /q app-clone


rem == app ==
hg init app
cd app
echo program>main.txt
hg add main.txt
hg commit -m "initial commit"
echo program+feature1>main.txt
hg commit -m "second commit, added a feature"
cd ..

rem == lib ==
hg init lib
cd lib
echo v1>lib.txt
hg add lib.txt
hg commit -m "initial commit"
echo v2>lib.txt
hg commit -m "second commit"
hg update 0
echo v3>lib.txt
hg commit -m "third commit"
echo v4>lib.txt
hg commit -m "fourth commit"
cd ..

rem == subrepos ==
cd app
hg clone ..\lib lib
echo lib = ..\lib >.hgsub
hg add .hgsub
hg commit -m "added subrepo"
cd ..

rem == clone ==
hg clone app app-clone

type app-clone\lib\lib.txt

Edit: Ok, I got my answer, thanks @VonC, I added the following section to my batch-file, above the rem == clone == line, and re-executed it, and now it locks the subrepo to the correct changeset.

rem == lock ==
cd app\lib
hg update 1
cd ..
hg commit -m "lock to second commit"
cd ..

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

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

发布评论

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

评论(2

葬花如无物 2024-09-09 06:59:21

未经测试,但您应该能够进入子存储库,将其内容更新到正确的提交(hg update),返回上一级(在主项目中)并提交。
这应该使用正确的提交更新 .hgsubstate

(极端的解决方法,自己更新 .hgsubstate ,但不建议这样做。)

hg subrepos 的全部想法(或Git 子模块)允许通过引用给定子存储库的固定 id 来进行依赖管理。如果创建子存储库时未给出 id,则会选择最新的 id(在您的情况下为 v4),但您可以签出您需要的任何 id。

实际上,此帖子甚至抱怨:

现在,提交递归地尝试在提交当前存储库之前提交子存储库。

这允许您:

  • 在子存储库中记录一些更改。
  • 使用子存储库的新状态 (id) 更新主项目的 .hgsubstate

Not tested, but you should be able to go within your subrepo, update its content to the right commit (hg update), go back up one level (in the main project) and commit.
That should update the .hgsubstate with the right commit.

(extreme workaround, update that .hgsubstate yourself, but that is not recommended.)

The all idea of hg subrepos (or Git submodules) is to allow a dependency management by referencing a fixed id for a given sub-repo. If no id is given when creating the subrepo, then the latest id is selected (v4 in your case), but you can checkout whatever id you need.

Actually, this thread even complains that:

Right now, commit recursively tries to commit subrepositories before committing the current repository.

That allows you to:

  • record some changes in the sub-repo.
  • update the .hgsubstate of the main project with the new state (id) of the subrepo.
你与昨日 2024-09-09 06:59:21

如果您没有明确选择这样做,您的子存储库修订将不会提前,因此您所要做的就是按照您最初的意愿进行设置。最初创建子存储库时,只需使用“-r”参数仅克隆到您想要的变更集:

rem == subrepos ==
cd app
hg clone -r CHANGESETYOUWANT ..\lib lib
echo lib = ..\lib >.hgsub
hg add .hgsub
hg commit -m "added subrepo"
cd ..

注意第三行的修改。

Your sub-repo revision won't be advanced without you explicitly choosing to do so, so all you have to do is set it up as you'd like initially. When initially creating the sub repo, just use a '-r' argument to clone only up to the changeset you'd like:

rem == subrepos ==
cd app
hg clone -r CHANGESETYOUWANT ..\lib lib
echo lib = ..\lib >.hgsub
hg add .hgsub
hg commit -m "added subrepo"
cd ..

note the modification on line three.

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