在子存储库中,hg update
指向您希望主存储库使用的变更集。然后,在主存储库中,发出hg ci
提交子存储库更改的问题。Mercurial 将使用子存储库的当前父变更集 ID 自动更新.hgsubstate
文件。
示例(Windows .bat 文件):
REM Create main repository
hg init Example
cd Example
echo >file1
hg ci -Am file1
cd ..
REM Create another repository
hg init Library
cd Library
echo >file2
hg ci -Am file2
cd ..
REM Clone the Library into the main repository
cd Example
hg clone ..\Library
REM and configure it as a subrepository.
echo Library=Library >.hgsub
REM Commit it.
hg ci -Am "Added Library sub repository."
REM Note .hgsubstate is updated with the current subrepo changeset.
type .hgsubstate
cd ..
REM Someone updates the original Library.
cd Library
echo >file3
hg ci -Am file3
cd ..
REM Main repo isn't affected. It has a clone of Library.
cd Example
hg status -S
REM Update to the latest library
cd Library
hg pull -u
cd ..
REM View the changes to the library in the main repo.
hg status -S
REM Commit the library update in the main repo.
hg ci -m "Updated library."
REM Note .hgsubstate is updated.
type .hgsubstate