2011-11-16 60 views
0

我想与Git存储库或子存储库like in Mercurial Share extension一起使用。如何在多个项目中共享.git文件夹?

所以,这里是我有:

mkdir orig 
cd orig 
echo "osthuaosteh" > abc 
git init --shared 
git add abc 
git commit -m 'init' 
cd .. 
mkdir another 

我怎样才能在another初始化回购,使其股与orig库?

我需要这个我想包括作为一个子库的大型图书馆。回购重量数百megs,所以我想重用一些文件夹。

更新:我想能够在不同的工作文件夹中有不同的修订版本。

+0

澄清:共享扩展共享多个工作副本之间的单个存储库。 –

+0

@Laurens Holst:这正是我需要的。 –

回答

2

我想问你的是:你真的需要共享存储库吗?

与Mercurial一样,git在制作本地克隆时会在存储库之间创建硬链接,从而仅占用很少的磁盘空间。例如: -

git clone http://example.org/repo repo 
git clone repo repo-copy1 
git clone repo repo-copy2 

repo-copy1repo-copy2库大多数文件的硬链接repo,并且不会占用额外的磁盘空间。只有工作副本中的文件才是真正的副本。

可以确认这种行为是这样的:

$ df -l 
Filesystem 512-blocks  Used Available Capacity Mounted on 
/dev/disk0s2 976101344 217966872 757622472 23% /
$ git clone --no-checkout repo repo-copy 
Cloning into repo-copy... 
done. 
$ du -cs repo-copy/.git 
63528 . 
63528 total 
$ df -l 
Filesystem 512-blocks  Used Available Capacity Mounted on 
/dev/disk0s2 976101344 217967536 757621808 23% /

正如你可以看到,克隆65880块库后(每512个字节),文件系统上的块数下降了仅664块。

如果从远程服务器克隆(子)存储库,则可能必须手动创建到其他本地克隆的硬链接;对于Mercurial,您可以使用relink扩展名;该git相当于也似乎是called that

+0

+1为解决这个问题,只需克隆本地回购:​​) – jweyrich

+0

太棒了!也会检查'relink'。 –

+0

这与“共享”不同,因为克隆现在是独立存储库。我怀疑磁盘空间在这里是问题,更多的是OP希望两个工作副本共享一个存储库。 –

1

随着混帐子模块,这将是(和你的榜样),路径another

git init # (to make another a git-repo) 
git submodule add ../orig orig # to make orig a submodule of another 
git commit # to commit the addition of the submodule 

。你有没有试过git submodule --help

+0

我读过它并且无法理解:“another/orig”中的.git文件夹(的部分)是否会被共享?我只是想节省空间和拉动交通。 –

+0

'git submodule add ../orig orig' =>'remote(origin)没有在.git/config中定义的url。我做'git status',说“没什么好提交”。 –

+0

子模块不一样(它们在hg中被称为子库)。共享扩展共享多个工作副本之间的单个存储库。 –

相关问题