如何合并两个不同的Git存储库? [英] How to Merge two different Git repositories?

查看:106
本文介绍了如何合并两个不同的Git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个Github存储库.一个存储库位于远程服务器上,另一个存储库位于本地服务器上.它们都具有不同文件和文件夹的不同提交历史.现在,我想将它们合并,以便将它们作为一个单独的存储库放在远程服务器上.请帮忙!

I have two Github repositories. One repository is on the remote server and another on the local server. Both of them have different commit histories of different files and folders. Now I wanted to merge both of them so that I can have both of them on the remote server as one single repository. Please help!

我一直在寻找各种建议的解决方案,例如:重置本地存储库的头,然后将远程存储库拉到同一目录,但似乎不起作用:

I have looked for various solutions suggesting as: reset the head of the local repository and then pull the remote repository on the same directory but it doesn't seem to be working:

git reset --soft head〜CommitSHA(本地存储库的首次提交)

git reset --soft head ~CommitSHA (First commit of the local repo)

git pull〜giturlofremoterepo(在同一目录中拉远程仓库)

git pull ~giturlofremoterepo (Pulling remote repo in the same directory)

推荐答案

创建一个新的git存储库并使用新的自述文件进行初始化.

Create a new git repository and initialize with a new README file.

$ mkdir merged_repo
$ cd merged_repo
$ git init 
$ touch README.md
$ git add .
$ git commit -m "Initialize new repo"

添加第一个远程存储库

$ git remote add -f first_repo `link_to_first_repo`
$ git merge --allow-unrelated-histories first_repo/master

创建一个子目录并将所有first_repo文件移动到该目录.

Create a sub directory and move all first_repo files to it.

$ mkdir first_repo
$ mv * first_repo/
$ git add .
$ git commit -m "Move first_repo files to first_repo directory"

添加第二个远程存储库

$ git remote add -f second_repo `link_to_second_repo`
$ git merge --allow-unrelated-histories second_repo/master

解决所有合并冲突,并按如下所示完成合并

Fix any merge conflicts and complete the merge as follows

$ git merge --continue

这篇关于如何合并两个不同的Git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆