git使用-如何与upstream 代码同步

git派生仓库后如何与upstream 代码同步

fork或者派生之后,如果upstream的代码发生改变,例如别人修复了一些问题,我们该如何同步过来呢?

1. 克隆代码库

[Tom@localhost ~]$ git  clone http://Tom@200.200.202.150/Tom/Realtek.git

2. 查看已关联的远程库,此时只有默认关联仓库origin

[Tom@localhost Realtek]$ git  remote -v
origin  http://Tom@200.200.202.150/Tom/Realtek.git (fetch)
origin  http://Tom@200.200.202.150/Tom/Realtek.git (push)
[Tom@localhost Realtek]$ 

3. 关联到upstream远程仓库

[Tom@localhost Realtek]$ git remote add test-isp  http://Tom@200.200.202.150/test-isp/Realtek.git
[Tom@localhost Realtek]$ git  remote -v
origin  http://Tom@200.200.202.150/Tom/Realtek.git (fetch)
origin  http://Tom@200.200.202.150/Tom/Realtek.git (push)
test-isp http://Tom@200.200.202.150/test-isp/Realtek.git (fetch)
test-isp http://Tom@200.200.202.150/test-isp/Realtek.git (push)

4. 抓取upstream

[Tom@localhost Realtek]$ git  fetch  test-isp
remote: Counting objects: 5058, done.
remote: Compressing objects: 100% (1988/1988), done.
remote: Total 5058 (delta 3471), reused 4239 (delta 3025)
Receiving objects: 100% (5058/5058), 6.88 MiB | 0 bytes/s, done.
Resolving deltas: 100% (3471/3471), done.
From http://200.200.202.150/test-isp/Realtek
 * [new branch]          master          -> test-isp/master
 * [new branch]          patch-1         -> test-isp/patch-1
 * [new branch]          revert-69dfefbe -> test-isp/revert-69dfefbe
 * [new branch]          revert-e7ff30a6 -> test-isp/revert-e7ff30a6
[Tom@localhost Realtek]$    

5. 查看抓取到的upstream远程仓库的修改历史,了解需要合并的内容。
master…origin/master 语法是一个日志过滤器,要求 Git 只显示所有在后面分支(在本例中是
origin/master)但不在前面分支(在本例中是 master)的提交的列表。

[Tom@localhost firmware]$ git log --no-merges master..test-isp/master

commit 9b98096bb73d8c08095a84209a9834db56a2ffd4
Author: wang.lihong <wang.lihong@test.com.cn>
Date:   Tue Jan 8 11:34:40 2019 +0800

    使用双等号==赋值错误

commit 69b12246295d25b4dbb1692c55df07364b8dbd32
Author: liu.ning <liu.ning@test.com.cn>
Date:   Tue Jan 8 08:57:59 2019 +0800

    修改pptp,l2tp建立移动用户VPN,绑定静态路由,断开VPN重新连接后,静态路由丢失的问题

commit dc8571a624ec5e6a43a8c9f42b51b8f5001e20e3
Author: liu.ning <liu.ning@test.com.cn>
Date:   Mon Jan 7 16:53:31 2019 +0800

    页面增加夏令时开关

6. 合并代码

[Tom@localhost Realtek]$ git merge test-isp/master
Updating db697cc65..92f388c70
Fast-forward
 README.md                                                                                                               |     24 +
 boards/rtl8197F/Makefile                                                                                                |     44 +-
 boards/rtl8197F/board-configuration.in                                                                                  |      3 +
 boards/rtl8197F/bsp/gpio.c                                                                                              |     12 +-
 boards/rtl8197F/config.busybox-1.13.RTL8197F_8812BR_8363NB_MP                                                           |    865 +
 boards/rtl8197F/config.busybox-1.13.RTL8197F_8812BR_8367R_ISP_CT_GW                                                     |     26 +-
 boards/rtl8197F/config.in                                                                                               |     10 +
 boards/rtl8197F/config.linux-3.10.RTL8197F_8812BR_8363NB_MP                                                             |   1850 +
 boards/rtl8197F/config.linux-3.10.RTL8197F_8812BR_8367R_ISP_CT_GW                                                       |     30 +-
 boards/rtl8197F/config.users.RTL8197F_8812BR_8363NB_MP                                                                  |    293 +
 boards/rtl8197F/config.users.RTL8197F_8812BR_8367R_ISP_CT_GW                                                            |     13 +-
 boards/rtl8197F/config.users.RTL8197F_8812BR_ISP_CT_GW                                                                  |      1 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/TZ                                                                        |      1 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/group                                                                     |      2 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/host.conf                                                                 |      1 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/hosts                                                                     |      3 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/init.d/rcS_AP                                                             |     71 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/init.d/rcS_GW                                                             |    149 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/inittab                                                                   |     11 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/iproute2/rt_tables                                                        |     13 +
 boards/rtl8197F/etc.RTL8197F_8812BR_8363NB_MP/mime.types                                                                |     66 +
 [Tom@localhost Realtek]$ 
 

7. 推送到自己的远程库中,更新代码

 [Tom@localhost Realtek]$ git push  origin master
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值