git子树从一个分支到同一个项目的几个位置

时间:2013-10-27 09:59:14

标签: git share git-submodules git-subtree

我有一个包含内容的git存储库:

 <shared files dir>/
        sharedFile1
        sharedFile2

我还有2个项目的额外git存储库B,每个项目都必须使用存储库A中的共享文件。因此文件结构将类似于:

Project_X
   <shared files dir>/
      sharedFile1
      sharedFile2
   <project X dirs>

Project_Y
   <shared files dir>/
      sharedFile1
      sharedFile2
   <project Y dirs>

我希望只在存储库A中更新共享文件,我需要允许project_X和Project_Y轻松获取这些更新。

实际上,符号链接可能是我需要的确切解决方案,但不幸的是,我使用的文件系统不支持它。

Git子树看起来也是合适的解决方案,但问题是我找不到如何将同一分支中的子树合并到同一个存储库中的2个位置。我成功地创建了我需要的文件结构:

git read-tree --prefix=Project_X/shared_files_dir/ -u shared_remote_branch
git read-tree --prefix=Project_Y/shared_files_dir/ -u shared_remote_branch

创建所需的文件结构(正如我在问题顶部所描述的那样),但尝试合并更新只会让我对我创建的最后一个子树进行更改:

git merge --squash -s subtree --no-commit shared_remote_branch

仅更新Project_Y / shared_files_dir /,而不更新来自shared_remote_branch的Project_X / shared_files_dir /。

我很感激任何想法。关于如何将子树从一个分支合并到两个位置(Project_X / shared_files_dir /)和(Project_Y / shared_files_dir /)或如何在任何其他方法中进行合并

1 个答案:

答案 0 :(得分:0)

从git1.8.2开始,您可以将 submodule 注册为following the latest commits of a given branch

所以我建议在第一个子树上采用这种方法,因为它允许:

  • 为shared_files repo维护单独的历史记录
  • 轻松更新到分支的最后一次提交

    git submodule update --remote
    

你甚至可以convert an existing submodule in order to have it trakc the latest of a branch


OP选择了simpler solution

  

我决定使用解决方法:

     
      
  • 在单独的仓库和
  • 中管理共享模块   
  • 在我的主仓库中添加post-checkout挂钩,将这些共享文件从共享仓库复制到主仓库。
  •   
     

我们是一个小团队,所以这种方法对我们来说最简单

相关问题