初始化一个新的回购。
从所有几个项目中复制所需版本的文件并将它们组合在一起。如有必要,您可以重新排列目录结构。并确保文件有预期的内容。
设置.gitignore
,.gitattribute
等。将它们全部添加并为新的回购做出第一次提交。
从几个项目中获取分支并将它们全部与选项-s ours
合并。策略仅合并历史,而不包含真实内容。
例子:
比方说,我们有RepoA,RepoB和RepoC,都包含分支master
。我们将合并三个分支的最新版本的文件。现在
git init RepoABC
cd RepoABC
#copy the files all RepoA, RepoB, RepoC and rearrange the directory structure if necessary.
#add .gitignore, .gitattribute, etc if necessary.
git add .
git commit -m 'new root for combining RepoA RepoB and RepoC'
git fetch origin_repoa master:repoa_master
git fetch origin_repob master:repob_master
git fetch origin_repoc master:repoc_master
git merge repoa_master repob_master repoc_master -s ours -m 'Merge and preserve the histories of RepoA, RepoB and RepoC, with merge strategy "ours"'
我们可以专注于新的回购的分行进行新的变化。历史是保留的,我们可以回顾他们。如果目录结构已重新排列,那么当我们第一次签出旧提交时,我们可能会遇到一个小问题。作为未跟踪文件签出后,新的文件夹和文件将保留。 git clean -df
会跳过它们,所以我们必须rm -rf
他们一次。
您是否得到了可帮助您解决问题的答案?如果是,您可以将其标记为答案。而且这也会使其他有类似问题的人受益。 –