欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

git----fork的项目保持与源项目同步更新

程序员文章站 2022-04-19 18:45:06
...

以windows为例

从fork项目开始

登录自己的github账号,fork一个项目,这里以 sharding-sphere 为例(顺便打一下广告^_^毕竟参与了项目)
1、登录github,打开项目主页sharding-sphere
2、点击页面的fork
3、fork完成可以在自己的github仓库中看到fork的项目sharding-sphere

clone项目到本地

1、git客户端选择
根据个人喜好,选择git shell或者纯桌面版git desktop。安装过程略,附下载地址 地址1地址2地址3

如果装的是纯桌面版,可以通过菜单打开git下载安装向导(省的搜索……)
git----fork的项目保持与源项目同步更新
git----fork的项目保持与源项目同步更新

2、在本地创建仓库存放的位置
本案例在d:\GitHub
3、克隆fork的项目到本地仓库
打开git shell

C:\Users\yueling>cd D:\GitHub
D:\GitHub>git clone https://github.com/yue530tom/sharding-sphere.git
Cloning into 'sharding-sphere'...
remote: Counting objects: 87775, done.
remote: Total 87775 (delta 0), reused 0 (delta 0), pack-reused 87775
Receiving objects: 100% (87775/87775), 16.87 MiB | 63.00 KiB/s, done.
Resolving deltas: 100% (42095/42095), done.                        ˻

查看clone项目

D:\GitHub> ls

目录: D:\GitHub

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----          2018/5/7     11:27            moco
d----         2018/5/11     12:08            sharding-sphere
d----          2018/5/9     18:01            shardingProxyPerf

同步更新到fork

1、添加新的远程仓库地址
查看你fork的远程仓库的地址

D:\GitHub> cd .\sharding-sphere
D:\GitHub\sharding-sphere [dev ≡]> git remote -v
origin  https://github.com/yue530tom/sharding-sphere.git (fetch)
origin  https://github.com/yue530tom/sharding-sphere.git (push)
sharding-sphere https://github.com/sharding-sphere/sharding-sphere.git (fetch)
sharding-sphere https://github.com/sharding-sphere/sharding-sphere.git (push)
D:\GitHub\sharding-sphere [dev ≡]> 

这里已经有项目的源地址了:sharding-sphere,如果没有,可以通过

git remote add 远端仓库别名 https://github.com/sharding-sphere/sharding-sphere.git 

来添加一个(仓库的别名,可以使用任何合法的名称,但建议用有标识意义的名称)
如:可以再添加一个别名为src的远程仓库

D:\GitHub\sharding-sphere [dev ≡]> git remote add src https://github.com/sharding-sphere/sharding-sphere.git
D:\GitHub\sharding-sphere [dev ≡]> git remote -v
origin  https://github.com/yue530tom/sharding-sphere.git (fetch)
origin  https://github.com/yue530tom/sharding-sphere.git (push)
sharding-sphere https://github.com/sharding-sphere/sharding-sphere.git (fetch)
sharding-sphere https://github.com/sharding-sphere/sharding-sphere.git (push)
src     https://github.com/sharding-sphere/sharding-sphere.git (fetch)
src     https://github.com/sharding-sphere/sharding-sphere.git (push)
D:\GitHub\sharding-sphere [dev ≡]>                                                                                    

2、同步更新
当原项目有更新的时候,将更新检入到本地。

打开git命令行工具并进入项目本地路径

D:\GitHub\sharding-sphere [dev ≡]>

执行git fetch src命令,检出src分支以及各自的更新

D:\GitHub\sharding-sphere [dev ≡]> git fetch src
remote: Counting objects: 4962, done.
remote: Compressing objects: 100% (611/611), done.
remote: Total 4962 (delta 2488), reused 3099 (delta 2431), pack-reused 1776
Receiving objects: 100% (4962/4962), 1.04 MiB | 209.00 KiB/s, done.
Resolving deltas: 100% (2845/2845), completed with 388 local objects.
From https://github.com/sharding-sphere/sharding-sphere
 * [new branch]          dev              -> src/dev
 * [new branch]          master           -> src/master
 * [new branch]          sharding-console -> src/sharding-console
D:\GitHub\sharding-sphere [dev ≡]>

切换到你的本地分支

D:\GitHub\sharding-sphere [dev ≡]> git checkout dev
Already on 'dev'
Your branch is up-to-date with 'origin/dev'.
D:\GitHub\sharding-sphere [dev ≡]>

合并src/dev分支和dev分支

D:\GitHub\sharding-sphere [dev ≡]>git merge src/dev
……
 rename {sharding-jdbc-core => sharding-jdbc}/src/test/resources/integrate/dataset/sharding/tbl/expect/update/tbl_9.xml (100%)
 rename {sharding-jdbc-core => sharding-jdbc}/src/test/resources/integrate/dataset/sharding/tbl/init/tbl.xml (100%)
 create mode 100644 sharding-jdbc/src/test/resources/integrate/dbtest/db/data-init.xml
 create mode 100644 sharding-jdbc/src/test/resources/integrate/dbtest/db/schema.xml
 create mode 100644 sharding-jdbc/src/test/resources/integrate/dbtest/db/sharding-rule.yaml
 create mode 100644 sharding-jdbc/src/test/resources/integrate/dbtest/dbtbl/data-init.xml
 create mode 100644 sharding-jdbc/src/test/resources/integrate/dbtest/dbtbl/schema.xml 
 ……    
D:\GitHub\sharding-sphere [dev ↑235]>                                       

将原项目中的更改更新到本地分支,这样就能使你的本地的fork分支与原项目保持同步

可以用git pull命令代替上面操作。作用:取回远程主机某个分支的更新,再与本地的指定分支合并
git pull [options] [ […]]

执行git push将本地分支的修改推送到远端fork的项目

D:\GitHub\sharding-sphere [dev ↑235]> git push
Counting objects: 4963, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1915/1915), done.
Writing objects: 100% (4963/4963), 1.17 MiB | 113.00 KiB/s, done.
Total 4963 (delta 2592), reused 4568 (delta 2455)
remote: Resolving deltas: 100% (2592/2592), completed with 62 local objects.
To https://github.com/yue530tom/sharding-sphere.git
   5ff9b0417..37cde1fee  dev -> dev
D:\GitHub\sharding-sphere [dev ≡]> git checkout dev
Already on 'dev'
Your branch is up-to-date with 'origin/dev'.
D:\GitHub\sharding-sphere [dev ≡]>

登录github确认是否已经更新了
git----fork的项目保持与源项目同步更新

git(非纯桌面版)的sync也可以实现项目的同步
选择需要比较的分支,选择配置的源仓库对应的分支,这点很重要比如选择src(上面已经用到过)
git----fork的项目保持与源项目同步更新

传送门:github web页面上直接同步源项目更新