专栏首页Aloys的开发之路如何合并两个Git仓库

如何合并两个Git仓库

假设有两个Git仓库:

  1. https://github.com/jiangxincode/thesis.git
  2. https://jiangxincode@bitbucket.org/jiangxincode/thesis.git

现在需要进行合并,保留双方的历史提交记录,并将1的内容删除,合并之后的内容推送到2中。

从Github上clone仓库到github目录:

$ git clone https://github.com/jiangxincode/thesis.git github
Cloning into 'github'...
remote: Enumerating objects: 29, done.
remote: Total 29 (delta 0), reused 0 (delta 0), pack-reused 29
Unpacking objects: 100% (29/29), done.

从Bitbucket上clone仓库到bitbucket目录:

$ git clone https://jiangxincode@bitbucket.org/jiangxincode/thesis.git bitbucket
Cloning into 'bitbucket'...
remote: Counting objects: 153, done.
remote: Compressing objects: 100% (150/150), done.
remote: Total 153 (delta 63), reused 0 (delta 0)
Receiving objects: 100% (153/153), 26.68 MiB | 2.64 MiB/s, done.
Resolving deltas: 100% (63/63), done.

在合并前根据实际情况分别处理两个目录的内容,并提交上传到远程仓库。

在仓库bitbucket中添加远程仓库github,命名为github

$ cd bitbucket/
$ git remote add github ../github/
$ git remote
github
origin

检出历史信息

$ git fetch github
warning: no common commits
remote: Enumerating objects: 32, done.
remote: Counting objects: 100% (32/32), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 32 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (32/32), done.
From ../github
 * [new branch]      master     -> github/master

基于github的master分支创建并检出新的分支,名字为github_master

$ git checkout -b github_master github/master
Switched to a new branch 'github_master'
Branch 'github_master' set up to track remote branch 'master' from 'github'.

切到仓库2的主线分支

$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

合并基于github创建的分支github_master到仓库bitbucket的master分支上

$ git merge github_master  --allow-unrelated-histories
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

此处可以看出出现了冲突,需要先解决冲突

$ git status
On branch master
Your branch is up to date with 'origin/master'.

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:

        new file:   tex-source/LICENSE
        new file:   tex-source/Makefile
        new file:   tex-source/abstract.tex
        new file:   tex-source/dtx-style.sty
        new file:   tex-source/englishabstract.tex
        new file:   tex-source/gbt7714-2005.bst
        new file:   tex-source/get_texmf_dir.sh
        new file:   tex-source/jiangxin.bib
        new file:   tex-source/jiangxin.tex
        new file:   tex-source/njulogo.eps
        new file:   tex-source/njuname.eps
        new file:   tex-source/njuthesis.cfg
        new file:   tex-source/njuthesis.cls
        new file:   tex-source/njuthesis.dtx
        new file:   tex-source/njuthesis.ins
        new file:   tex-source/preface.tex

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both added:      .gitignore

$ git add .gitignore

$ git commit
[master 3d6cb22] Merge branch 'github_master'

最后push本地所有分支到bitbucket

$ git push origin master
Enumerating objects: 37, done.
Counting objects: 100% (37/37), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (35/35), 320.42 KiB | 3.56 MiB/s, done.
Total 35 (delta 9), reused 0 (delta 0)
To https://bitbucket.org/jiangxincode/thesis.git
   f92ef9e..3d6cb22  master -> master

$ git push origin github_master:github_master
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create pull request for github_master:
remote:   https://bitbucket.org/jiangxincode/thesis/pull-requests/new?source=github_master&t=1
remote:
To https://bitbucket.org/jiangxincode/thesis.git
* [new branch]      github_master -> github_master

此时查看本地和远程的所有分支

$ git branch -a
  github_master
* master
  remotes/github/master
  remotes/origin/HEAD -> origin/master
  remotes/origin/github_master
  remotes/origin/master
  origin/master

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • oracle表空间不足相关问题解决办法

    oracle 临时表空间和数据表空间 Oracle临时表空间主要用来做查询和存放一些缓冲区数据。临时表空间消耗的主要原因是需要对查询的中间结果进行排序。重启数据...

    用户1221057
  • Peer Code Reviews Made Easy with Eclipse Plug-In

    Origin Article: Peer Code Reviews Made Easy with Eclipse Plug-In Origin Author: ...

    用户1221057
  • Linux快捷键

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinn...

    用户1221057
  • MySQL MHA 典型使用场景

    Since MHA Manager uses very little CPU/Memory resources, you can manage lots of ...

    Leshami
  • MySQL高可用之MHA(二)

    2、MHA引入keepalived(MySQL服务进程挂掉时通过MHA 停止keepalived) 要想把keepalived服务引入 MHA,我们只需要修改切...

    小手冰凉
  • git仓库删除所有提交历史记录,成为一个干净的新仓库 转

    把旧项目提交到git上,但是会有一些历史记录,这些历史记录中可能会有项目密码等敏感信息。如何删除这些历史记录,形成一个全新的仓库,并且保持代码不变呢?

    双面人
  • Flink是如何kafka读取数据的

    版权声明:本文为博主原创,欢迎转载,转载请标明出处 Blog Address:http://blog.csdn.net/jsjsjs1789 https...

    shengjk1
  • JedisSentinelPool源码分析

    1. 概述 Redis-Sentinel作为官方推荐的HA解决方案,Jedis也在客户端角度实现了对Sentinel的支持,主要实现在JedisSentinel...

    JavaEdge
  • torch.hub

    Pytorch Hub is a pre-trained model repository designed to facilitate research re...

    于小勇
  • SAP CRM settype Key structure determination

    For background of this issue, please read Implementation guide for Genil Model a...

    Jerry Wang

扫码关注云+社区

领取腾讯云代金券