将Git repo A移动到具有完整历史记录的Git repo B(非空)中

时间:2017-02-06 06:41:21

标签: git macos version-control

我想将我的所有文件从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 fatal:myDirectory/: 'myDirectory' is outside repository Could not get the commits"时收到git filter-branch --subdirectory-filter muDirectory -- --all

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

1 个答案:

答案 0 :(得分:3)

  • 进入repoB并使用repoA URL添加新的遥控器(例如repoA)。
  • 使用branchA结帐新分支(例如,repoA/master history)。
  • Git将所有文件夹/文件移动到新的子目录RepoA中。命令git mv <src> <dest>
  • branchA中提交您的更改。
  • Checkout 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的子目录。