如何使用 git 将多个项目分叉到一个存储库中?
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能对 git-submodule 功能感兴趣。引用自此处:
You may be interested in git-submodule functionality. Quote from here:
您始终可以使用“
git remote add
”来添加更多存储库作为源。You can always use "
git remote add <name> <url>
" to add more repositories as source.有一种可能性我从未“真正”尝试过,但这可能会很有效。
假设您有三个项目,创造性地命名为 Proj1、Proj2 和(猜猜看)Proj3。我们还可以说,其中全部或部分依赖于外部库,例如一个名为 Lib1.dll 的库,另一个名为 SuperLib.dll 的库。
首先,对于文件夹结构,我会执行以下操作:
然后您将在每个 ProjX 文件夹上创建一个存储库:
然后您将为整个内容创建一个存储库:
对于 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:
Then you would create one repository on each of the ProjX folders:
Then you would create a repository for the whole thing:
The contents of this repository, for git, would be the
Libs
folder and its contents, thebuild_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 togit commit
on Proj1, and then you would go to the whole thing and thengit 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!
我想我应该使用 子树合并策略。我必须实际尝试一下,看看效果是否良好。如果事实证明这是一个好方法,我会将这个答案标记为已接受。
与此同时,我仍然愿意接受建议。
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.