常见问题解答和hginit.com对于帮助我从svn过渡到hg非常有用。
然而,当谈到以颠覆的外部方式使用Hg的子存储库功能时,我已经尝试了所有的标志,并且无法复制svn外部的良好行为。
以下是我想要做的最简单的例子:
Init“lib”存储库 该存储库永远不会被用作独立存储库;它始终包含在main中 存储库,作为子存储库。
初始化一个或多个包含存储库 为了使示例简单,我将“初始化”一个名为“main”的存储库
让“main”包含“lib”作为子库
重要的是 - 在这里,我无法工作: 当我修改“main / lib”中的文件时,我推送修改, 然后该更改被推送到“lib”存储库 - 而不是副本 在“主要”里面。
命令行胜于雄辩。我在这个主题上尝试了很多变化,但这里是要点。如果有人能够在命令行中回复,我将永远感激不尽!
$ cd / home / moi / hgrepos ##我在我的主服务器上存储我的hg存储库
$ hg init lib
$ echo“foo”> LIB / lib.txt
$ hg add lib
$ hg ci -A -m“Init lib”lib
$ cd / home / moi / hgrepos
$ hg init main
$ echo“foo”>主/ main.txt
$ hg add main
$ cd main
$ hg clone ../lib lib
$ echo“lib = lib”> .hgsub
$ hg ci -A -m“Init main”。
这一切都运行正常,但是当我复制“主”存储库并制作本地存储库时 修改“main / lib”中的文件,并推送它们,更改被推送到“main / lib”, 不要“lib”。
$ / home / moi / hg-test
$ hg clone ssh://moi@www.moi.com/hgrepos/lib lib
$ hg clone ssh://moi@www.moi.com/hgrepos/main main
$ cd main
$ echo foo>> LIB / lib.txt
$ hg st
M lib.txt
$ hg com -m“修改后的lib.txt,来自主要仓库”lib.txt
$ hg push
它表明我已经修改了lib中文件的COPY,而不是lib库中的文件。如果这是按照我希望的方式工作,则推送到hgrepos / lib,而不是hgrepos / main / lib。即,我会看到:
$ hg push
推送到ssh://moi@www.moi.com/hgrepos/lib
提前谢谢!
Emily in Portland
答案 0 :(得分:8)
问题出在您的.hgsub文件中。它指向lib repo的位置,所以如果lib是main的兄弟,它应该是:
lib=../lib
您的hg add lib
和hg add main
行也没有意义。在main和lib之外的repo是被添加的那些?您在/home/moi/hgrepos
进入时正在运行它们。
这是你的脚本,有一些调整:
+ cd /home/ry4an/hgtest
+ hg init lib
+ echo foo
+ cd lib
+ hg commit -A -m Init lib
adding lib.txt
+ cd /home/ry4an/hgtest
+ hg init main
+ echo foo
+ cd main
+ echo lib=../lib
+ hg clone ../lib
destination directory: lib
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ hg add .hgsub main.txt
+ hg commit -m Init main: initial file and a .hgsub
committing subrepository lib
+ cd /home/ry4an/hgtest
+ hg clone main main-clone
updating to branch default
pulling subrepo lib
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ cd main-clone
+ echo foo
+ hg commit -m Modified lib.txt, from inside the main repos
committing subrepository lib
+ hg push
pushing to /home/ry4an/hgtest/main
pushing subrepo lib
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
要通过ssh://执行此操作,您只需进行一次更改即可。克隆主要仓库时,将hg clone main main-clone
更改为hg clone ssh://host/hgtest/main main-clone
- 克隆主要库会自动克隆库 - 这就是subrepo的好处。
这是工作日志:
+ cd /home/ry4an/hgtest
+ hg init lib
+ echo foo
+ cd lib
+ hg commit -A -m Init lib
adding lib.txt
+ cd /home/ry4an/hgtest
+ hg init main
+ echo foo
+ cd main
+ echo lib=../lib
+ hg clone ../lib
destination directory: lib
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ hg add .hgsub main.txt
+ hg commit -m Init main: initial file and a .hgsub
committing subrepository lib
+ cd /home/ry4an/hgtest
+ hg clone ssh://localhost/hgtest/main main-clone
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is 0c:58:d6:d3:d3:16:14:ee:3b:be:01:bc:c7:3c:92:0b.
Are you sure you want to continue connecting (yes/no)? yes
ry4an@localhost's password:
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 3 changes to 3 files
updating to branch default
pulling subrepo lib
ry4an@localhost's password:
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
remote: Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
+ cd main-clone
+ echo foo
+ hg commit -m Modified lib.txt, from inside the main repos
committing subrepository lib
+ hg push
ry4an@localhost's password:
pushing to ssh://localhost/hgtest/main
pushing subrepo lib
ry4an@localhost's password:
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
答案 1 :(得分:1)
糟糕,对不起前一个回答中的格式。这里再次格式化了!
因此,以下是大多数人将面临的两种情况:
A)在完全本地的情况下使用子存储库。 这基本上就是Ryan的解决方案。 我想只有独自工作的开发人员会在这艘船上。
cd /home/moi/hgrepos
hg init lib
cd lib
echo foo > lib.txt
hg ci -A -m Init
cd /home/moi/hgrepos
hg init main
cd main
echo foo > main.txt
echo lib = ../lib > .hgsub
hg clone ../lib
hg add .hgsub main.txt
hg ci -m Init
cd /home/moi/hgrepos
hg clone main main-clone
cd main-clone/lib
echo "Modified while on main trunk" >>lib.txt
hg commit -m "Modified lib.txt, while on main trunk"
hg push
cd /home/moi/hgrepos/lib
hg update
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
cat lib.txt
foo
Modified while on main trunk
B)在ssh上使用子库。
我想大多数在团队中工作的开发人员都会在这艘船上。
1)设置lib
cd /home/moi/hgrepos
hg init lib
cd lib
echo foo > lib.txt
hg ci -A -m Init
2)设置主
cd /home/moi/hgrepos
hg init main
cd main
echo foo > main.txt
echo lib=ssh://moi@www.moi.com/hgrepos/lib > .hgsub
hg clone ssh://moi@www.moi.com/hgrepos/lib lib
hg add .hgsub main.txt
hg ci -m Init
3)克隆lib到hgtest dir
cd /home/moi/hgtest
hg clone ssh://moi@www.moi.com/hgrepos/lib lib
4)克隆主要到hgtest目录
cd /home/moi/hgtest
hg clone ssh://moi@www.moi.com/hgrepos/main main
5)在主干上修改lib.txt
cd /home/moi/hgtest/main/lib
echo "Modified while on main trunk" >>lib.txt
hg commit -m "Modified lib.txt, while on main trunk"
hg push
6)验证lib库中的lib.txt是否已更改
cd /home/moi/hgtest/lib
hg pull
hg update
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
cat lib.txt
foo
Modified while on main trunk