[英]Merge git repo into branch of another repo
Given repo Foo and repo Bar.给定 repo Foo 和 repo Bar。 I want to merge Bar with Foo, but only into a separate branch, called
baz
.我想将 Bar 与 Foo 合并,但只能合并到一个名为
baz
的单独分支中。
git switch -c baz
<= put the Bar repo here. git switch -c baz
<= 把 Bar 仓库放在这里。
You can't merge a repository into a branch .您不能将存储库合并到分支中。 You can merge a branch from another repository into a branch in your local repository.
你可以在你的本地仓库合并来自另一个存储库分支到一个分支。 Assuming that you have two repositories,
foo
and bar
both located in your current directory:假设您有两个存储库,
foo
和bar
都位于当前目录中:
$ ls
foo bar
Change into the foo
repository:切换到
foo
存储库:
$ cd foo
Add the bar
repository as a remote and fetch it:将
bar
存储库添加为远程并获取它:
$ git remote add bar ../bar
$ git remote update
Create a new branch baz
in the foo
repository based on whatever your current branch is:根据您当前的分支在
foo
存储库中创建一个新分支baz
:
$ git switch -c baz
Merge branch somebranch
from the bar
repository into the current branch:将
bar
存储库中的somebranch
分支合并到当前分支中:
$ git merge --allow-unrelated-histories bar/somebranch
( --allow-unrelated-histories
is not required prior to git version 2.9) (在 git 2.9 版之前不需要
--allow-unrelated-histories
)
Updated with "real-life" commands:更新了“现实生活”命令:
Start from your repo directory, make sure your working copy is clean (no files changed, added or removed).从您的 repo 目录开始,确保您的工作副本是干净的(没有更改、添加或删除文件)。
Make a new branch:新建一个分支:
git checkout -b <my-branch>
Add the secondary remote, then fetch it:添加辅助遥控器,然后获取它:
git remote add <repo-name> git@github.com:xxx/<repo-name>.git
git remote update
Merge one of their branches in your current branch:将他们的分支之一合并到您当前的分支中:
git merge <repo-name>/<their-branch>
If you don't know which <their-branch>
you want, then go for master
如果你不知道你想要哪个
<their-branch>
,那就去找master
If you are sure you want to accept all remote changes and avoid conflicts ( overwrite yours ) then you can specify -X theirs
as option for git merge
in the last step.如果您确定要接受所有远程更改并避免冲突(覆盖您的),那么您可以在最后一步指定
-X theirs
作为git merge
选项。
If you want to add it in a subdirectory then probably you should probably use git submodules如果你想将它添加到一个子目录中,那么你可能应该使用git submodules
Using the guide from larsks, I was able to do this using SourceTree.使用 larsks 的指南,我能够使用 SourceTree 做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.