我正在阅读 subrepos,并在本地运行了一些测试,到目前为止似乎工作正常,但我有一个问题。
我如何指定/控制我想为特定子存储库使用哪个变更集?
例如,假设我有以下两个项目:
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 ..
最佳答案
未测试,但您应该能够进入您的子仓库,将其内容更新为正确的提交(hg update
),返回上一级(在主项目中)并提交。
这应该用正确的提交更新 .hgsubstate
。
(极端解决方法,update that .hgsubstate
yourself,但不推荐这样做。)
hg subrepos的所有想法(或 Git 子模块)允许通过引用给定子仓库的 固定 id 来进行依赖管理。如果在创建子仓库时没有给出 id,则会选择最新的 id(在你的情况下是 v4),但你可以 checkout 你需要的任何 id。
实际上,this thread甚至提示:
Right now, commit recursively tries to commit subrepositories before committing the current repository.
这允许您:
- 记录子仓库中的一些更改。
- 使用子存储库的新状态 (id) 更新主项目的
.hgsubstate
。
关于Mercurial Subrepos,如何控制我想将哪个变更集用于子仓库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2867417/