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

问题描述 投票:0回答:1

我有两个存储库,假设存储库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)

我想在不丢失历史记录的情况下将文件从Repo A合并(或变基)到Repo B / src。合并之后,当我查看历史记录时,我想同时查看Developer X和Y的更改。这可能吗?如果是,请指导我如何执行此操作。

我看过其他SO帖子,并尝试添加远程仓库...等。但是这些都没有涵盖这种情况。我的GIT版本是2.21.0。

git merge rebase remote-repository
1个回答
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

这假定文件没有重叠。

© www.soinside.com 2019 - 2024. All rights reserved.