如何将N个git存储库合并为一个保存历史记录? [英] How to merge N git repositories into one preserving their histories?

查看:88
本文介绍了如何将N个git存储库合并为一个保存历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,它由几个单独的Git仓库组成(合并几个Maven项目,每个项目都有一个单独的Git仓库)。



现在我要创建一个Git然后将每个存储库的内容放入其子目录中,保留它们各自的历史记录(将多个Maven项目合并到一个多模块Maven项目中)。

我该怎么做?



我尝试将答案应用于类似的SO问题


  1. 我们调用单个存储库 P1 - PN 和统一存储库 U

  2. 创建仓库 U
  3. U git checkout -b P1 >中创建分支 P1
  4. P1 目录中运行命令 git remote add U git@myuser.beanstalkapp.com:/U.git

  5. P1 目录中, git push U P1

当我这样做时,最后一步:

 错误:src refspec ccplogic不匹配任何。 
错误:无法将某些参考文献推送到'git@myuser.beanstalkapp.com:/U.git'


Submodulesrel =nofollow> git子模块,但听起来好像您只需要一个存储库就可以了。



您可以创建一个存储库使用名为 git-subtree 的脚本,它现在是mainline git的一部分,尽管位于 contrib 目录。要安装 git-subtree 脚本,将它保存为名称 git-subtree PATH 。 (如果这有效,那么 git subtree 会给你一个用法信息。)



假设你创建了一个新的空如下所示:

  mkdir示例
cd示例
git init
touch .gitignore
git add .gitignore
git commit -m'Initial commit'

然后对于其他每个版本库,可以执行下列操作(假设版本库位于URL git://wherever/whatever.git ),并且您希望它的<$ c

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ > git remote add whevs-remote git://wherever/whatever.git
git fetch whevs-remote
git subtree add --prefix = whevs whevs-remote / master

然后对每个其他存储库执行相同的操作。


I have a project, which consists of several separate Git repositories (merge several Maven projects each with a separate Git repository).

Now I want to create one Git repository and put the contents of each of those repositories into sub-directories of it, preserving their respective histories (merge several Maven projects into one multi-module Maven project).

How can I do that?

I tried to apply the answer to a similar SO question:

  1. Let's call individual repositories P1-PN and the unified repository U.
  2. Create repository U.
  3. Create branch P1 in U (git checkout -b P1).
  4. In P1 directory, run the command git remote add U git@myuser.beanstalkapp.com:/U.git.
  5. In P1 directory, git push U P1.

When I do this, I get following error in the last step:

error: src refspec ccplogic does not match any.
error: failed to push some refs to 'git@myuser.beanstalkapp.com:/U.git'

解决方案

One way of doing this is by adding each repository as a git submodule, but it sounds as if you want a single repository instead.

You can make a single repository with the history of all the other repositories by using a script called git-subtree, which is now part of mainline git, albeit in the contrib directory. To install the git-subtree script, save it to the name git-subtree somewhere on your PATH. (If that worked, then git subtree should give you a usage message.)

Assuming you created a new empty repository with something like:

mkdir example
cd example
git init
touch .gitignore
git add .gitignore
git commit -m 'Initial commit'

Then for each other repository, you can do something like the following (assuming that the repository is at the URL git://wherever/whatever.git and you want its master branch to appear in the subdirectory whevs):

git remote add whevs-remote git://wherever/whatever.git
git fetch whevs-remote
git subtree add --prefix=whevs whevs-remote/master

Then do the same for each other repository.

这篇关于如何将N个git存储库合并为一个保存历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆