ramlife

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

需求

仓库 A 正常使用,现在找到一些仓库 A 使用之前的数据,希望把这些数据也放到仓库中,并有相关记录。

解决方法

  • 如果 A 提交不多,那就把仓库从头开始提交数据
  • 使用 rebase --onto,把旧数据先提交作为一个分支,然后把原来的 master 分支 rebase 到这个新分支上去。问题是,冲突解决很烦,原来 A 的每个提交都需要解决冲突
  • git merge --strategy ours --allow-unrelated-histories --no-commit frontend/master 使用类似这个命令强行合入,但是合并后,提交按照时间降序排列。
  • 把旧数据管理为仓库 B,然后把仓库 B 作为一个 A 的 old 分支,然后在 readme 中做说明即可。想看旧数据就切到 old 分支上。

操作步骤

  • 把旧数据整体并提交到新建的本地仓库 B, git init --bare
  • 然后在 A 的项目中添加 本地仓库 B 为 remote, 并命名为 old, git remote add old c:/xxxx/xxx
  • 拉取 B 的数据, git fetch old
  • 切换到旧数据,并创建分支 old1, git checkout -b old1 old/master
  • 把旧数据的分支 old1 推送到仓库 A 中的分支 old 上去,git push origin old1:old

参考:

git 两个仓库之间的历史提交之间能合并么?
https://www.zhihu.com/question/326060985

合并两个git仓库并保留提交记录
https://www.cnblogs.com/suanec/p/8418924.html

合并两个Git仓库的历史提交记录
https://blog.csdn.net/weixin_30569033/article/details/98724869

合并两个Git仓库的历史提交记录
https://blog.csdn.net/Charles_7c/article/details/125951834

Git学习笔记(十) 改变历史
https://blog.csdn.net/agul_/article/details/7843182

git rebase 的 --onto选项的用法疑问?
https://www.zhihu.com/question/60279937

妙用git rebase --onto指令
https://www.cnblogs.com/chjbbs/p/6425350.html

在Git历史记录中插入新提交
https://blog.csdn.net/dlz00001/article/details/106640532

Inserting a new commit in the Git history
https://blog.frankel.ch/inserting-new-commit-git-history/

git push 命令
https://www.runoob.com/git/git-push.html

posted on 2023-01-26 17:12  ramlife  阅读(264)  评论(0编辑  收藏  举报