问题描述
我有一个项目,它由几个单独的Git仓库组成(合并几个Maven项目,每个项目都有一个单独的Git仓库)。
现在我要创建一个Git然后将每个存储库的内容放入其子目录中,保留它们各自的历史记录(将多个Maven项目合并到一个多模块Maven项目中)。
我该怎么做?
我尝试将答案应用于:
- 我们调用单个存储库
P1
-PN
和统一存储库U
。 - 创建仓库
U
。 在 - 在
P1
目录中运行命令git remote add U [email protected]:/U.git
。 - 在
P1
目录中,git push U P1
。
U
( git checkout -b P1
>中创建分支 P1
) 当我这样做时,最后一步:
错误:src refspec ccplogic不匹配任何。
错误:无法将某些参考文献推送到'[email protected]:/U.git'
您可以创建一个存储库使用名为 git-subtree
的脚本,它现在是mainline git的一部分,尽管位于 contrib
目录。要安装,将它保存为名称 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:
- Let's call individual repositories
P1
-PN
and the unified repositoryU
. - Create repository
U
. - Create branch
P1
inU
(git checkout -b P1
). - In
P1
directory, run the commandgit remote add U [email protected]:/U.git
. - 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 '[email protected]:/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存储库合并为一个保存历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!