将不相关的存储库导入到另一个存储库分支

编程入门 行业动态 更新时间:2024-10-27 20:25:07
本文介绍了将不相关的存储库导入到另一个存储库分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经尝试过许多关于stackoverflow的答案,但是似乎没有一个能完全按照我的要求工作.基本上,我有一个主存储库,我创建了一个主存储库(例如:功能"),并且需要向该功能"分支添加另一个完全不相关的存储库作为文件夹.我还需要具有导入存储库中的历史记录以进行合并.我将如何去做?

I have tried many answers on stackoverflow but none of them seem to work exactly how I want it. Basically I have a main repository that I have created a branch of (eg: 'feature') and I need to add another totally unrelated repository as a folder to this 'feature' branch. I need to have the history from the importing repository to merge as well. How would I go about doing this?

一个小例子:

"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"

推荐答案

我假设您要将合并的存储库添加到新目录中.

I assume that you are adding the merged repository to a new directory.

尝试以下命令

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不会跟踪空目录.)

(You need to add the temp file because Git does not track empty directories.)

这将为您提供定期的合并提交,同时包含双方的所有历史记录.

This will give you a regular merge commit with all history from both sides.

更多推荐

将不相关的存储库导入到另一个存储库分支

本文发布于:2023-11-11 11:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578352.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将不   分支   导入到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!