目前开发是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. Linux shell编程 -test

    test 命令的格式非常简单 test condition condition 是test命令要测试的一系列参数和值.当用在if-then 语句中时,test 命令看起来是这样的 if test co ...

  2. Python3.6 连接MySQL(二)转载

    安装mysqlclient库 错误:OSError: mysql_config not found 解决:  方案一 ln -s /usr/local/mysql/bin/mysql_config / ...

  3. Nginx负载均衡的5种策略(转载)

    Nginx的upstream目前支持的5种方式的分配 轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. upstream backserver { s ...

  4. java从pdf中提取文本

    一(单文件转换):下载pdfbox包,百度搜pdfbox.(fontbox-1.8.16.jar和pdfbox-app-1.8.16.jar) package pdf; import java.io. ...

  5. Rewrite JSON project with Fetch

    上传 JSON 数据 使用fetch()来发布json编码的数据. var url = 'https://example.com/profile'; var data = {username: 'ex ...

  6. 安卓开发学习笔记(四):Android Stuidio无法实现隐式Intent是为什么?

    一.首先检查我们的代码: FirstActivity.java(主活动程序当中的代码):Button3监听器后面的代码就是我们隐式Intent的业务逻辑所在了,大家可以往下面看看,大概在代码的第57行 ...

  7. [Swift]LeetCode611. 有效三角形的个数 | Valid Triangle Number

    Given an array consists of non-negative integers, your task is to count the number of triplets chose ...

  8. [Swift]LeetCode678. 有效的括号字符串 | Valid Parenthesis String

    Given a string containing only three types of characters: '(', ')' and '*', write a function to chec ...

  9. [Swift]LeetCode830. 较大分组的位置 | Positions of Large Groups

    In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...

  10. [Swift]LeetCode874. 模拟行走机器人 | Walking Robot Simulation

    A robot on an infinite grid starts at point (0, 0) and faces north.  The robot can receive one of th ...