代码之家  ›  专栏  ›  技术社区  ›  Oblomov

Git:将两个独立的回购合并为一个,而不丢失历史记录

  •  0
  • Oblomov  · 技术社区  · 7 年前

    我得到了两个具有以下文件夹结构的回购:

    > folder1
      >.git
      > file1
      > file2
    
    > folder2
      >.git
      > file3
      > file4
    

    > repo
       >.git
       > folder1
          > file1
          > file2
        > folder1
          > file3
          > file4
    

    我如何在Git中做到这一点,而不丢失任何一个以前独立的存储库的历史?

    2 回复  |  直到 7 年前
        1
  •  1
  •   mity    7 年前

    我想以下几点应该行得通:

    1. 调整回购 folder1 拥有正确的内部结构。

      cd folder1
      mkdir folder1
      git mv file1 folder1/file1
      git mv file2 folder1/file2
      git commit -a
      
    2. 回购协议也是如此 folder2

      cd folder2
      mkdir folder2
      git mv file3 folder2/file3
      git mv file4 folder2/file4
      git commit -a
      
    3. git pull

      cd folder1  # the top one, not the one we have created in the 1st step.
      git pull /path/to/folder2
      

      或者,将两者合并为新创建的回购协议。

      mkdir repo
      cd repo
      git init
      git pull /path/to/folder1
      git pull /path/to/folder2
      
        2
  •  1
  •   Mr. Em    7 年前

    你可以找到解决方案 here .

    1. 从您的回购中合并
    2. 移动文件