我已经尝试过许多关于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.
更多推荐
将不相关的存储库导入到另一个存储库分支
发布评论