[英]Pushing subtrees in a git repo
I'm quite new to Git: I come from SVN and there I found really powerfull the :external feature. 我对Git很新:我来自SVN,在那里我发现了非常强大的外部功能。 Here in Git I haven't find something similar: 在Git中我找不到类似的东西:
So the scenario is this: I have a project, in which I want to include some libraries. 所以场景是这样的:我有一个项目,我希望在其中包含一些库。 I want the possibility to change all these libraries and pushing them in their own repos. 我希望有可能改变所有这些库并将它们推送到自己的回购中。 Moreover some of this libraries are subdirs of bigger projects (for example if a project includes also demos or readme files, I won't include those dirs in my project). 此外,这些库中的一些是较大项目的子目录(例如,如果项目还包括演示或自述文件,我将不会在我的项目中包含这些目录)。
How can I do that? 我怎样才能做到这一点?
I've tried: 我试过了:
Well, if you've reached this point, thanks for your patience, now I'd like something else to try, because right now my conclusion is: "subtree pushing isn't allowed in Git" ç_ç 好吧,如果你已达到这一点,感谢你的耐心,现在我想要别的东西尝试,因为现在我的结论是:“Git中不允许子树推送”ç_ç
Couple of remarks from the comments: 评论中的几点评论:
So I recommend: 所以我建议:
git checkout git checkout
parent repo
+
+--> main project
+
+-> mainDir1
+-> mainDir2
+--> lib1
+
+-> lib1Dir1
+-> lib1Dir2
+--> lib2
+
+-> lib2Dir1
+-> lib2Dir2
And your own project directory structure (for instance) 和你自己的项目目录结构(例如)
+--> main project (symlink to ../parent/main project)
+
+-> mainDir1
+-> mainDir2
+-> lib1Dir1 (symlink to ../parent/lib1/lib1Dir1)
+-> lib1Dir2 (symlink to ../parent/lib1/lib1Dir2)
+-> lib2Dir2 (symlink to ../parent/lib1/lib2Dir2)
(note there is no lib2Dir1
(for instance) because in your actual project you don't need it) (注意没有lib2Dir1
(例如)因为在你的实际项目中你不需要它)
VonC's solution is neat, but it has a disadvantage: There is no good way of capturing a configuration of your project+libraries at a point in time. VonC的解决方案很简洁,但它有一个缺点:在某个时间点没有很好的方法来捕获项目+库的配置。
If you need to set up your project again, you'll need to checkout your project + the libraries, but they may all be on different branches and commits to what you had before. 如果您需要再次设置项目,则需要签出项目+库,但它们可能都在不同的分支上,并且承诺您之前拥有的内容。
So, if you follow VonC's suggestion, maybe create tags in each of the repos at the point when you make a release of your project, so that you can at least check them out again at the same point. 因此,如果您遵循VonC的建议,可能会在您发布项目时在每个回购中创建标记,以便您至少可以在同一点再次检查它们。
Otherwise, always move forwards and never check out an older version. 否则,请始终向前移动,不要查看旧版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.