目前开发是2个仓库,线上仓库online_a(对应的branch分支为online),测试环境online_b(对应的branch分支为demo),测试环境需要时刻保持onine_a上的最新稳定稳定代码同步过来。如何合并呢?特此记录下:
在测试仓库onine_b 上执行:

1:测试仓库添加远程生产仓库(切换到自己的测试仓库下执行以下命令,比如我的当期测试online_b.git)

git remote add online_a git@github.com:fantasy/online_a.git //将online_a作为远程仓库,添加到online_b中,设置别名为online_a(自定义,这里我是为了方便区分仓库名)

2:从远程仓库下载,这时我们弄个新的

git fetch online_a //从online_a仓库中抓取数据到本仓库,注意这里是上面设置的别名
$ git fetch online-a
remote: Counting objects: , done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta )
Receiving objects: % (/), 2.44 MiB | 214.00 KiB/s, done.
Resolving deltas: % (/), completed with local objects.
From git@github.com:fantasy/online_a.git* [new branch] demo -> online-backend/demo
* [new branch] online -> online-backend/online
* [new tag] demo-last-bad -> demo-last-bad
* [new tag] demo-last-ok -> demo-last-ok
* [new tag] v2.-beta -> v2.-beta
* [new tag] v2.-days -> v2.-days
* [new tag] v2.-dist -> v2.-dist
* [new tag] v2.-dist -> v2.-dist
* [new tag] v2.-nosmartbid -> v2.-nosmartbid
* [new tag] v2.2demo -> v2.2demo
* [new tag] v2.-bad-smartbid -> v2.-bad-smartbid
* [new tag] demo-no-score -> demo-no-score
* [new tag] tmp-repay-v1 -> tmp-repay-v1
* [new tag] tmp-repay-v2 -> tmp-repay-v2
* [new tag] transfer-dep-last -> transfer-dep-last
* [new tag] transfer-dep-ok -> transfer-dep-ok

3:将online_a仓库抓去的online分支作为新分支checkout到本地,新分支名设定为online_repo1

$ git checkout -b online_repo1 online-a/online  //注意这里也是别名online_a
Switched to a new branch 'online_repo1'
Branch 'online_repo1' set up to track remote branch 'online' from 'online-a'.

4:切换回本地测试的online_b的demo分支

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

5:将online_repo1合并入demo分支

git merge online_repo1

6:解决冲突:

git add .
git commit -m "合并"
git push online_repo1 online_a:online //上传到远程库
git checkout demo
git merge online_repo1
git branch -d online_repo1
总结:
  1. 大致思路是伪造远程的repo1仓库为repo2的一个分支,然后合并进来;
  2. 若是文件有冲突、或要建立子目录,建议在repo1中先解决,再进行如上操作。

git合并两个不同的仓库的更多相关文章

  1. Git 合并两个不同的仓库

    目录 第一步. 下载需要合并的分支 第二步. 添加需要合并远程仓库 第三步. 把base远程仓库中数据抓取到本仓库 第四步. checkount切换到base分支上,命名为 asf 第五步. 合并 总 ...

  2. git 合并两个仓库

    我有两个仓库,一个是gitbook在写一本 一个是放在github的垃圾,这个是我想要开个人网站,但是做的还是不行https://github.com/lindexi/lindexi.github.i ...

  3. 如何用 Git 合并两个库,并保留提交历史

    转载自 https://segmentfault.com/a/1190000000678808 背景 一个中型规模项目,开始规划时就打算采用 C/S 架构,后端是单纯的 API 服务,前端在 Web ...

  4. Git 合并两个分支内容

    1,将开发分支代码合入到master中 git checkout dev #切换到dev开发分支 git pull git checkout master git merge dev #合并dev分支 ...

  5. git 合并两个分支的某个文件

    软件开发基本都是多个feature分支并行开发,而在上线前有可能某个分支的开发或测试还没有完成,又或者是产品调整,取消了该分支功能的上线计划,我们在release前不合并该分支即可,然而如果该分支中的 ...

  6. 合并两个git仓库

    现有两个git仓库ekt_zy.ekt_zijian,需要把ekt_zijian项目中的代码合并到ekt_zy项目中. 1 将ekt_zijian作为远程仓库.添加到ekt_zy中,设置别名为ziji ...

  7. Git提交到多个远程仓库(多看两个文档)

    Git提交到多个远程仓库(多看两个文档) 一.总结 一句话总结: 二. Git提交到多个远程仓库(多看两个文档) 有两种做法,先看第一种 一.通过命令行进行操作 例如我有下面两个仓库: Mybatis ...

  8. git合并不同仓库下的分支

    1.把lib合并到pro $ git remote -v origin git@192.168.1.1:lib.git (fetch) origin git@192.168.1.1:lib.git ( ...

  9. Git合并不同url的项目

    本文由云+社区发表 作者:工程师小熊 摘要:为了让项目能实现Git+Gerrit+Jenkin的持续集成,我们把项目从Git上迁移到了Gerrit上,发现有的同事在老Git提交代码,因为Gerrit做 ...

随机推荐

  1. mysql里的数据库引擎, 编码格式

    针对数据库里即使设置了varchar类型的字段, 值输入中文报错的情况,是因为数据库的默认编码类型不支持汉字输入. utf-8 可以编译全球通用的所有语言符号. 由1-6个可变字节组成,有非常严格的排 ...

  2. WARN [wxpay java sdk] - report fail. reason: report.mch.weixin.qq.com:80 failed to respond

    最近小程序接口 tomcat日志经常出现此类警告 WARN [wxpay java sdk] - report fail. reason: report.mch.weixin.qq.com:80 fa ...

  3. emWin监护仪界面设计,含uCOS-III和FreeRTOS两个版本

    第5期:监护仪界面设计 配套例子:V6-908_STemWin提高篇实验_监护仪界面设计(uCOS-III)V6-909_STemWin提高篇实验_监护仪界面设计(FreeRTOS) 例程下载地址:h ...

  4. 分门别类总结Java中的各种锁,让你彻底记住

    概念 公平锁/非公平锁 公平锁是指多个线程按照申请锁的顺序来获取锁. 非公平锁是指多个线程获取锁的顺序并不是按照申请锁的顺序,有可能后申请的线程比先申请的线程优先获取锁.有可能,会造成优先级反转或者饥 ...

  5. #Java学习之路——面试题

    (一)[基础知识梳理——JAVAse部分]Java中的变量和常量        在程序中存在大量的数据来代表程序的状态,其中有些数据在程序的运行过程中值会发生改变,有些数据在程序运行过程中值不能发生改 ...

  6. [Swift]LeetCode474. 一和零 | Ones and Zeroes

    In the computer world, use restricted resource you have to generate maximum benefit is what we alway ...

  7. [Swift]LeetCode1010. 总持续时间可被 60 整除的歌曲 | Pairs of Songs With Total Durations Divisible by 60

    In a list of songs, the i-th song has a duration of time[i] seconds. Return the number of pairs of s ...

  8. logback.xml sql语句输出

    在使用springBoot框架之后,日志配置文件变成了logback.xml,输出sql语句的方法为: <!-- 打印sql语句 --> <logger name="com ...

  9. Spark中SQL列和并为一行

    在使用数据库的时候,需要将查询出来的一列按照逗号合并成一行. 原表名字为 TABLE ,表中的部分原始数据为: +---------+------------------------+ | BASIC ...

  10. Pycharm使用教程(三)(非常详细,非常实用)

    1. 汉化:把resources_zh.jar拷贝到PyCharm的安装目录下的lib目录,重启Pycharm即可. (resources_zh.jar汉化包关注本账号获取:链接: https://p ...