【问题标题】:Move Git repo A into Git repo B (Not empty) with complete history将 Git 存储库 A 移至具有完整历史记录的 Git 存储库 B(非空)
【发布时间】:2017-06-23 00:56:03
【问题描述】:

我想将我的所有文件从 Git Repo A 移动到具有完整历史记录的 Git Repo B。 Git B 已经包含另一个项目文件。我尝试了几种方法,例如

How to move files from one git repo to another (not a clone), preserving history

How to move files from one git repo to another preserving history using `git format-patch`and `git am`

我尝试通过终端执行所有提交。但我在执行git filter-branch --subdirectory-filter muDirectory -- --all 时收到"git filter-branch fatal:myDirectory/: 'myDirectory' is outside repository Could not get the commits"

我需要详细的指导,逐步将所有文件从一个存储库移动到另一个存储库。非常感谢任何帮助,在此先感谢。

【问题讨论】:

  • 将一个存储库移动到另一个 非空 存储库后,您期望什么?
  • 我的回购 B 已经有 Proj1 和 Proj2。现在我希望将 RepoA 作为 Proj3 移动到 RepoB,其中包含来自 RepoA 的所有提交历史记录。

标签: git macos version-control


【解决方案1】:
  • 进入repoB 并使用repoA URL 添加一个新遥控器(例如repoA)。
  • 使用repoA/master history 结帐新分支(例如branchA)。
  • Git 将所有文件夹/文件移动到新的子目录RepoA。命令git mv <src> <dest>
  • branchA 中提交您的更改。
  • 签出master 分支并合并branchA 分支。

按照命令:

# go into repoB master branch
$ git remote add repoA <repoA-url>
$ git remote -v                     # confirm repoA is added named 'repoA'

$ git fetch repoA
$ git checkout -b branchA repoA/master
$ git mv <folder/file> repoA/<folder/file>     # repeat untill all files/folders are moved
$ git commit -am 'Moved repoA folder/file into repoA dir' 


$ git checkout master
$ git merge branchA

$ git add .
$ git commit -m 'Added repoA into repoA directory'
$ git push origin master

Git 子树:您也可以使用git subtree 来执行此操作:

$ git subtree add --prefix=repoA/ <repoA-url> master

master branch of repoA拉到一个名为repoA的子目录中。

【讨论】:

  • 我越来越致命:在 git pull repoA master 后拒绝合并不相关的历史记录错误
  • 你能把你的commands &amp; error details附在OP(原帖)吗?
  • 顺便说一句,您想将RepoA 添加到您的RepoB 作为单独的存储库,还是仅添加根目录中的所有文件夹/文件?
  • 就像根目录下的文件夹
  • @SasiM --allow-unrelated-histories.
猜你喜欢
  • 2022-08-07
  • 2023-03-17
  • 2011-08-25
  • 1970-01-01
  • 2014-01-03
  • 1970-01-01
  • 2011-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多