如何在多个项目之间共享.git文件夹?

发布于 2024-12-16 02:16:05 字数 457 浏览 1 评论 0原文

我想使用 Git 存储库或子存储库就像 Mercurial Share 扩展中的那样

所以,这就是我所拥有的:

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

如何在 another 中初始化一个存储库,以便它与 orig 共享存储库?

我需要这个作为一个大库,我想将其包含为子存储库。该存储库重达数百兆,因此我想重用一些文件夹。

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

I want to work with Git repositories or sub-repositories like in Mercurial Share extension.

So, here's what I have:

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

How can I initialize a repo in another so that it shares the repository with orig?

I need this for a big library that I want to include as a sub-repository. The repo weighs hundreds of megs, so I want to reuse some of the folders.

Update: I want to be able to have different revisions in different working folders.

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

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

发布评论

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

评论(2

此刻的回忆 2024-12-23 02:16:05

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

与 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 等效项似乎也被称为

What I would ask you is: do you really need to share the repository?

Like Mercurial, git creates hard-links between repositories when you make a local clone, resulting in only little extra disk space consumption. E.g.:

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

Most files in the repo-copy1 and repo-copy2 repositories will hard-link to repo, and will not consume extra disk space. Only the files in the working copy are actual copies.

You can confirm this behaviour like this:

$ 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%    /

As you can see, after cloning a 65880-block repository (of 512 bytes each), the block count on the file system went down by only 664 blocks.

If you clone a (sub)repository from a remote server you may have to manually create the hard links to other local clones; for Mercurial you would use the relink extension for that; the git equivalent also seems to be called that.

晌融 2024-12-23 02:16:05

对于 git-submodules ,这将在路径 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 吗?

With git-submodules that would be (and with your example) in path 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

. Have you tried git submodule --help?

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