我在 stackoverflow 上尝试了很多答案,但似乎没有一个能完全按照我想要的方式工作。基本上我有一个主存储库,我创建了一个分支(例如:“功能”),并且我需要添加另一个完全不相关的存储库作为此“功能”分支的文件夹。我还需要从导入存储库中获取历史记录来合并。我该怎么做呢?
一个小例子:
"Project to import"
- "XXX folder"
- "YYY file"
"Main repository" - "feature-branch"
- "ABC folder"
- "Feature folder" - #How it should look after merging
-- "Imported files from other repo"
我假设您正在将合并的存储库添加到新目录中。
尝试以下命令
git remote add unrelated <url-of-other-repo>
git fetch unrelated <branch-in-other-repo>
mkdir -p <path/to/new/code>
touch <path/to/new/code/>temp
git add <path/to/new/code/>temp
git commit -m 'Bring in new directory'
git merge --no-ff unrelated/<branch-in-other-repo> -s recursive -Xsubtree=<path/to/new/code>
git rm <path/to/new/code/temp>
git commit --amend --no-edit
git remote remove unrelated
(您需要添加临时文件,因为 Git 不跟踪空目录。)
这将为您提供包含双方所有历史记录的定期合并提交。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)