如何使用 git 将多个项目分叉到一个存储库中?

发布于 2024-08-11 06:11:34 字数 164 浏览 10 评论 0原文

我有 3 个项目想要 fork。它们都是相互关联的——改变一个可能需要改变另一个。因为它们都是相关的,所以我想为分支创建 1 个存储库,同时保持从每个原始版本中提取更新的能力。

我将如何设置我的 git 存储库?

这些都是初步的想法,所以如果这是疯狂/愚蠢的,我不会感到惊讶。是吗?

I have a 3 projects I'd like to fork. They're all related to each other - changing one will likely require a change to another. Because they're all related, I'd like to create 1 repository for the forks, while maintaining the ability to pull down updates from each original.

How would I setup my git repository?

These are preliminary thoughts so I wouldn't be surprised if this is crazy/stupid. Is it?

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

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

发布评论

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

评论(4

沉鱼一梦 2024-08-18 06:11:34

您可能对 git-submodule 功能感兴趣。引用自此处

Git 的子模块支持允许
存储库包含,作为
子目录,签出
外部项目。子模块维护
他们自己的身份;子模块
support 仅存储子模块
存储库位置和提交 ID,所以
其他克隆的开发者
包含项目(“超级项目”)
可以轻松克隆所有子模块
相同的修订版。部分结帐
超级项目的可能性:你
可以告诉 Git 不克隆、克隆一些或
所有子模块。

You may be interested in git-submodule functionality. Quote from here:

Git's submodule support allows a
repository to contain, as a
subdirectory, a checkout of an
external project. Submodules maintain
their own identity; the submodule
support just stores the submodule
repository location and commit ID, so
other developers who clone the
containing project ("superproject")
can easily clone all the submodules at
the same revision. Partial checkouts
of the superproject are possible: you
can tell Git to clone none, some or
all of the submodules.

枕梦 2024-08-18 06:11:34

您始终可以使用“git remote add”来添加更多存储库作为源。

You can always use "git remote add <name> <url>" to add more repositories as source.

冰葑 2024-08-18 06:11:34

有一种可能性我从未“真正”尝试过,但这可能会很有效。

假设您有三个项目,创造性地命名为 Proj1Proj2 和(猜猜看)Proj3。我们还可以说,其中全部或部分依赖于外部库,例如一个名为 Lib1.dll 的库,另一个名为 SuperLib.dll 的库。

首先,对于文件夹结构,我会执行以下操作:

MyCode\
    build_all.bat
    Docs\
        [...]
    Libs\
        Lib1.dll
        SuperLib.dll
    Proj1\
        [...]
    Proj2\
        [...]
    Proj3\
        [...]

然后您将在每个 ProjX 文件夹上创建一个存储库:

cd \MyCode\Proj1
git init
cd \MyCode\Proj2
git init
cd \MyCode\Proj3
git init

然后您将为整个内容创建一个存储库:

cd \MyCode
git init

对于 git,此存储库的内容将是Libs 文件夹及其内容、build_all.bat 构建脚本和 3 个子项目。

因此,一旦您更改源代码(例如 Proj1\Main.cs),整个内容将看不到修改。您必须在 Proj1 上进行 git commit,然后您将转到整个内容,然后git commit(现在 git 将能够可以看到 Proj1 已被修改)。

使用这种方法,整个事件的历史记录将简单地说明 ProjX 何时被修改,但它不会直接跟踪单个文件。然而,正如预期的那样,ProjX 上的存储库将像往常一样跟踪每个文件。

如果您在“真实项目”上尝试一下,请告诉我结果!

祝你好运!

There's one possibility I've never tried "for real" but that might work well.

Let's say you have three projects creatively named Proj1, Proj2 and (guess it) Proj3. Let's also say that all or some of them depend on external libraries, for example one called Lib1.dll and another called SuperLib.dll.

First, for the folder structure, I'd do something like:

MyCode\
    build_all.bat
    Docs\
        [...]
    Libs\
        Lib1.dll
        SuperLib.dll
    Proj1\
        [...]
    Proj2\
        [...]
    Proj3\
        [...]

Then you would create one repository on each of the ProjX folders:

cd \MyCode\Proj1
git init
cd \MyCode\Proj2
git init
cd \MyCode\Proj3
git init

Then you would create a repository for the whole thing:

cd \MyCode
git init

The contents of this repository, for git, would be the Libs folder and its contents, the build_all.bat build script, and 3 subprojects.

So once you change your source code, let's say Proj1\Main.cs, the whole thing wouldn't see the modification. You would have to git commit on Proj1, and then you would go to the whole thing and then git commit it (now git will be able to see that Proj1 has been modified).

Using this method, the history of the whole thing would simply state when the ProjX were modified, but it would not directly keep track of individual files. Howver, as expected, the repository on ProjX would keep track of every file, as usual.

If you give it a try on a "real project", let me know the results!

Good luck!

檐上三寸雪 2024-08-18 06:11:34

我想我应该使用 子树合并策略。我必须实际尝试一下,看看效果是否良好。如果事实证明这是一个好方法,我会将这个答案标记为已接受。

与此同时,我仍然愿意接受建议。

I think I should be using the subtree merge strategy. I'll have to actually try it out and see if it works well. I'll mark this answer as accepted if this turns out to be a good approach.

In the mean time, I'm still open for suggestions.

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