如何在保持提交历史的同时将多个存储库迁移到一个单存储库中? [英] How to migrate multiple repositories into a mono-repo while maintaining commit history?
问题描述
我正在尝试将一些Git存储库迁移到一个monorepo中.
I'm trying to migrate a few Git repositories into one monorepo.
我有两个项目存储库,我们称它们为 project1
和 project2
.在我的monorepo中,我想有一个 projects
目录,其中包含两个子目录,分别是 project1
和 project2
.每个子目录都应包含相应项目的文件,并保留Git历史记录.
I have two project repositories, let's call them project1
and project2
. In my monorepo, I want to have a projects
directory with two subdirectories, project1
and project2
. Each subdirectory should contain the files from the corresponding project, with the Git history maintained.
使用标准的Git命令甚至可以做到吗?
Is this even possible with standard Git commands?
注意:我看过Lerna- lerna import
确实可以满足我的需要,但不幸的是,它仅适用于JS项目,而我的一个项目是Ruby项目.
Note: I have looked at Lerna - lerna import
does exactly what I need, but unfortunately it only works with JS projects, and one of my projects is a Ruby project.
推荐答案
是的,您可以使用git命令来实现.
Yes, you can use git commands to achieve.
将两个仓库存放在一个子仓库 project1
和 project2
中,您需要将文件移动到仓库的project1/project2文件夹中,提交更改,然后将它们组合在一起.详细步骤如下:
Migarte two repos into a monorepo into subfolder project1
and project2
, you need to move files into project1/project2 folder of a repo, commit changes and then combine them together. Detail steps as below:
### 1.将文件分别移到project1和project2文件夹中在第一个存储库(例如 repo1
)中,将文件移动到 project1
文件夹中,如下所示:
###1. Move files into project1 and project2 folders separately
In the first repo (such as repo1
), move files into project1
folder as below:
# In local repo1
mkdir project1
mv * project1
git add .
git command -m 'move files into project1 folder'
git push
在第二个存储库中(例如 repo2
),将文件移动到project2文件夹中,如下所示:
In the second repo (such as repo2
), move files into project2 folder as below:
# In local repo2
mkdir project2
mv * project2
git add .
git command -m 'move files into project2 folder'
git push
### 2.将两个存储库迁移到monorepo
###2. migrate the two repos into a monorepo
在任何本地存储库中(例如在本地 repo1
中),执行以下命令:
In any of a local repo (such as in local repo1
), execute below commands:
# In local repo1
git remote add repo2 <URL for repo2> -f
git pull repo2 master --allow-unrelated-histories
这篇关于如何在保持提交历史的同时将多个存储库迁移到一个单存储库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!