GIT 将存储库与另一个存储库中的文件夹合并,而不会丢失历史记录



我有两个存储库,假设存储库 A 和存储库 B 的结构如下所示:

Repo A (there are many files in each repo. I am just showing 2 files for example):
|
|
|---Test1.cs  (It has some changes made by X Developer)
|---Test2.cs  (It has some changes made by X Developer)
Repo B:
|
|
|---src
|
|
|---Test1.cs  (It has some changes made by Y Developer)
|---Test2.cs  (It has some changes made by Y Developer)

我想将文件从存储库 A 合并(或变基(到 Repo B/src,而不会丢失历史记录。合并后,当我查看历史记录时,我希望看到开发人员 X 和 Y 的变化。 这可能吗?如果是,请指导我如何做到这一点。

我查看了其他 SO 帖子并尝试添加远程存储库...等。但这些不包括这种类型的场景。我的 GIT 版本是 2.21.0。

您可以为此使用普通合并,但您必须使用merge --allow-unrelated-histories来允许不相关的历史记录合并。

例如:

cd target-repository
# we work on master
git checkout master
# add the repository as a remote
git remote add other /path/to/source-repo
# fetch the remote repository, which will create other/master
git fetch other
# merge the histories, specifiy --allow-unrelated-histories to avoid the related history check
git merge --allow-unrelated-histories other/master

这假定文件不重叠。

最新更新