简体   繁体   English

在git repo中推送子树

[英]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中我找不到类似的东西:

  • submodules are perfect for adding project modules that are not always required. 子模块非常适合添加并非总是需要的项目模块。 They must be initialized after the repo cloning and you can't include only a subdir of the original project. 它们必须在repo克隆后初始化,并且不能只包含原始项目的子目录。
  • subtrees are really good for adding libraries (they also allow subdir inclusion), but pushing them is a real pain. 子树非常适合添加库(它们也允许子目录包含),但推送它们真的很痛苦。

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: 所以我建议:

  • loading (git checkout) the parent repo and all its submodules loading(git checkout)父repo及其所有子模块
  • creating elsewhere the correct structure, with symlink to the submodules (or subdirectories of the submodules in order to achieve what you need. 在其他地方创建正确的结构,使用符号链接到子模块(或子模块的子目录,以实现您的需要。
  • go back periodically to the git ain parent repo in order to detect any changes (dones from the other directory structure created outside of Git) in order to commit and push all submodules modifs, and then commit and push the parent repo. 定期回到git ain parent repo以检测任何更改(来自Git之外创建的其他目录结构的dones),以便提交并推送所有子模块modif,然后提交并推送父repo。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM