简体   繁体   English

将较新的Git仓库附加到较旧的仓库以合并两个历史记录

[英]Append a newer Git repo onto an older repo to combine both histories

I've got two related git repositories on GitHub that should really be one. 我在GitHub上有两个相关的git存储库应该真的是一个。 How do I combine both projects into one project, in a way that satisfies the following context: 如何将两个项目组合到一个项目中,以满足以下上下文的方式:

  • Each repo currently only has a master branch. 每个仓库目前只有一个主分支。
  • A is the older repo, B is the newer repo. A是较旧的回购,B是较新的回购。
  • A is the canonical repo (ie: repo A has the name that I ultimately want this tool to be called, so I want all future work, after B has been appended to A, to be done in repo A). A是规范的回购(即:回购A的名称我最终希望调用此工具,因此我希望将所有未来的工作,在B附加到A之后,在回购A中完成)。
  • After B has been appended to A, A should exist, B should be deleted. B附加到A后,A应存在,B应删除。
  • I don't want to put one repo as a subdirectory of the other, I want to combine the two repos as if they were one repo all along. 我不想把一个repo作为另一个的子目录,我想把两个repos结合起来,好像它们一直是一个repo。
  • I want this change to the git history of A to be permanent so that folks don't have to pull refs, but instead just clone the updated repo A and get everything as expected. 我希望对A的git历史进行此更改是永久性的,以便人们不必拉引用,而只是克隆更新的repo A并按预期获得所有内容。
  • There are 3 similar files between the two repos: .gitignore , readme.md , and package.json . 两个repos之间有3个类似的文件: .gitignorereadme.mdpackage.json

You can: 您可以:

Here is a clean way to do it: 这是一个干净的方法:

From your local A repository 从您当地的A存储库

git remote add b https://github.com/your-username/your-b-repo.git
git fetch b
git checkout -b b-master b/master
git rebase master
# fix conflicts if any
git checkout master
git merge b-master
git branch -d b-master

Explanation 说明

  1. Add your secondary remote repository called b to the local primary repository 将名为b辅助远程存储库添加到本地主存储库
  2. Fetch everything from it 从中获取所有内容
  3. Create a new local branch that matches the b/master called b-master and checkout to it 创建一个与b / master相匹配的新本地分支,称为b-master并将其签出
  4. Place everything you did in the B repository after everything you did in the A repository using the rebase command 使用rebase命令将您在A存储库中执行的所有操作放在B存储库中
    1. Fix the conflits during the rebase 在rebase期间修复conflits
  5. Checkout your master branch (on A) 检查你的master分支(在A上)
  6. merge the master branch (A) to the b-master branch (B) master分支(A)合并到b-master分支(B)
  7. Delete the now useless b-master branch 删除现在无用的b-master分支

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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