git - GIT MERGE 将一个 repo 与另一个 repo 中的文件夹合并,而不会丢失历史记录
问题描述
我有两个存储库,假设 Repo A 和 Repo 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。
解决方案
您可以为此使用普通合并,但您必须使用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
这假设文件不重叠。
推荐阅读
- cordova - Ionic 3 无法获得 repo Appodeal
- python - 在 sudo su 模式下导入 python 包 pytube 面临问题
- r - OfficeR/RVG 包中的 HighcharteR 可能吗?
- graphql - 瑜伽graphql服务器+棱镜服务器:多租户
- angular - 角度材料输入验证未按预期工作
- css - 创建弯曲的页脚
- javascript - Javascript检查数组json中是否存在值
- swift - 如何正确构建 NSPredicate 以从具有特定日期标签的 CoreData 对象创建值数组?
- html - Ruby on Rails:如何让 Each_do_with_index 不更新我的对象的索引?
- xamarin.forms - 以 Xamarin 形式下载文件