在git repo中推送子树 [英] Pushing subtrees in a git repo

查看:280
本文介绍了在git repo中推送子树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Git来说很新:我来自SVN,在那里我发现了真正强大的外部功能。在Git中,我还没有发现类似的东西:




  • 子模块非常适合添加不是始终需要。它们必须在repo克隆后初始化,并且不能只包含原始项目的子目录。

  • 子树非常适合添加库(它们也是允许subdir包含),但推动它们是一个真正的痛苦。


    所以情况是这样的:我有一个项目,其中我想要包括一些图书馆。我希望有可能改变所有这些库,并将它们推入自己的仓库。此外,其中一些库是较大项目的子集(例如,如果一个项目也包含演示文件或自述文件,我不会在这个项目中包含这些目录)。



    我怎么做到的?



    我试过了:



    好吧,如果你已经达到了这一点,感谢你的耐心,现在我想还有其他的东西可以尝试,因为现在我的结论是:在Git中不允许使用子树推送ç_ç

    解决方案

    评论来自评论:


    • git子模块与svn外部不同

    • 对子模块进行的任何修改

    • 规划git迁移的存储库布局说明你不能总是直接使用子模块作为目录结构,
      所以我建议:


      • 加载(git checkout)父级回购及其所有子模块
      • 在其他地方创建正确的结构,符号链接到子模块(或子模块的子目录以实现你需要什么。
      • 定期回到git ain parent repo中,以便检测任何更改(来自在Git之外创建的其他目录结构的done),以便提交并推送所有子模块然后提交并推送父回购。


      git结帐

       父母回购
      +
      + - >主项目
      +
      + - > mainDir1
      + - > mainDir2
      + - > lib1
      +
      + - > lib1Dir1
      + - > lib1Dir2
      + - > lib2
      +
      + - > lib2Dir1
      + - > lib2Dir2

      您自己的项目目录结构(例如)

        +  - >主项目(符号链接到../parent/main项目)
      +
      + - > mainDir1
      + - > mainDir2
      + - > lib1Dir1(符号链接到../parent/lib1/lib1Dir1)
      + - > lib1Dir2(符号链接到../parent/lib1/lib1Dir2)
      + - > lib2Dir2(符号链接到../parent/lib1/lib2Dir2)

      (注意没有 lib2Dir1 (例如),因为在你的实际项目中你不需要它)


      I'm quite new to Git: I come from SVN and there I found really powerfull the :external feature. Here in Git I haven't find something similar:

      • 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.
      • 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" ç_ç

      解决方案

      Couple of remarks from the comments:

      So I recommend:

      • loading (git checkout) the parent repo and all its submodules
      • 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 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)

      这篇关于在git repo中推送子树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆