在gitlab上,每个人需要fork远程分支到自己的目录下,然后在自己的目录下进行开发,开发完成将代码上传到自己的远程仓库,然后通过gitlab服务器发起merge request,同步到主仓库中。为了更快掌握git相关操作,这里设置一项训练,如下:
假设远程仓库为player_oop,本地克隆后为my_player_oop,远程仓库比本地更新,需要同步远程代码到本地,这里不采用git pull的方式,采用如下方法,目的是将下面的命令逐步使用熟练。
以下是实际操作过程:
#查看当前目录文件
root@liufei-VirtualBox:/home/liufei/learngit/abc# ls
build build.sh bus cfg glue inc install_file patch products public_inc qinPlayerMain.cpp src util
#查看当前状态,这里显示落后6个commit,那是因为我已经处理过了,这里只是演示过程
root@liufei-VirtualBox:/home/liufei/learngit/abc# git st
On branch master
Your branch is behind 'origin/master' by 6 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
#查看当前分支
root@liufei-VirtualBox:/home/liufei/learngit/abc# git branch
* master
#查看远程分支情况
root@liufei-VirtualBox:/home/liufei/learngit/abc# git remote -v
origin git@pms.lemon.com:liufei/player_oop.git (fetch)
origin git@pms.lemon.com:liufei/player_oop.git (push)
#新增远程主仓库路径
root@liufei-VirtualBox:/home/liufei/learngit/abc# git remote add upstream git@pms.lemon.com:player/player_oop.git
#获取主仓库内容
root@liufei-VirtualBox:/home/liufei/learngit/abc# git fetch upstream
From pms.lemon.com:player/player_oop
* [new branch] master -> upstream/master
* [new branch] release -> upstream/release
#创建并切换到fork分支
root@liufei-VirtualBox:/home/liufei/learngit/abc# git checkout -b fork
Switched to a new branch 'fork'
#将远程主仓库中同步到fork分支上,这里使用是rebase
root@liufei-VirtualBox:/home/liufei/learngit/abc# git rebase upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded fork to upstream/master.
#同步完成后的fork分支,对比master分支,创建patch文件,并放置到patch目录下。
root@liufei-VirtualBox:/home/liufei/learngit/abc# git format-patch -M master -o patch
patch/0001-add-subtitle-open-close-api.patch
patch/0002-fix-hdmi-spdif-audio-control-add-subtitle-functions.patch
patch/0003-fix-display-zoom-subtitle-bug.patch
patch/0004-31090-fix-default-audioChannel-for-topway.patch
patch/0005-fix-primer-is-the-same-with-live.patch
patch/0006-remove-booking-type-from-player.patch
#切换到master分支
root@liufei-VirtualBox:/home/liufei/learngit/abc# git checkout master
Switched to branch 'master'
Your branch is behind 'origin/master' by 6 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
#检查生成的patch是否OK
root@liufei-VirtualBox:/home/liufei/learngit/abc# git apply --stat patch/*.patch
glue/java/java/org/ngb/media/MediaManager.java | 22 ++++----
.../org/ngb/media/SubtitleLanguageControlImpl.java | 10 ++--
glue/java/jni/org_ngb_media_MediaManager.cpp | 57 ++++++++++++++++++++
3 files changed, 75 insertions(+), 14 deletions(-)
bus/client/player_bus_client.c | 38 ++++++++
bus/service/qinPlayerBusServer.cpp | 27 ++++++
glue/java/jni/org_ngb_media_MediaManager.cpp | 2
glue/src/qinMediaPlayerGlue.cpp | 22 ++++-
inc/qinDVBPlayer.h | 2
inc/qinPlayerBase.h | 12 +--
inc/qinPlayerUtil.h | 9 ++
public_inc/api/istb_player_api.h | 4 +
public_inc/glueapi/qinMediaPlayerGlue.h | 1
public_inc/type/istb_player_type.h | 35 ++++++--
src/qinAudioSetting.cpp | 74 ++++++++++++++--
src/qinDVBPlayer.cpp | 93 +++++++++++++++++---
src/qinPlayerApi.cpp | 39 +++++++-
src/qinPlayerResourceManager.cpp | 28 ++++++
src/qinPlayerUtil.cpp | 66 ++++++++++++++
15 files changed, 399 insertions(+), 53 deletions(-)
glue/java/jni/org_ngb_media_MediaManager.cpp | 30 +++---
.../java/jni/org_ngb_util_setting_VideoSetting.cpp | 38 ++++++++
glue/src/qinMediaPlayerGlue.cpp | 95 +++++++++++++++++++-
public_inc/glueapi/qinMediaPlayerGlue.h | 2
src/qinDVBPlayer.cpp | 18 +++-
5 files changed, 157 insertions(+), 26 deletions(-)
glue/src/qinMediaPlayerGlue.cpp | 12 +--
inc/qinDVBPlayer.h | 3 -
public_inc/type/istb_player_type.h | 1
src/qinDVBPlayer.cpp | 78 +++++++++++-----
4 files changed, 60 insertions(+), 34 deletions(-)
src/qinDVBPlayer.cpp | 20 +++-
1 file changed, 12 insertions(+), 8 deletions(-)
public_inc/type/istb_player_type.h | 67 --------------
1 file changed, 67 deletions(-)
#使用check远程,查看打patch是否成功,这里显示有问题,但是使用git am仍然能打成功,一个疑点???
root@liufei-VirtualBox:/home/liufei/learngit/abc# git apply --check --ignore-space-change --ignore-whitespace patch/*.patch
error: patch failed: glue/java/jni/org_ngb_media_MediaManager.cpp:1584
error: glue/java/jni/org_ngb_media_MediaMana,ger.cpp: patch does not apply
#查看打patch之前的日志,用于确认patch是否打成功
root@liufei-VirtualBox:/home/liufei/learngit/abc# git log -1
commit 8c39c8137e8265b35eb7c835ff30f7ac5db13f2f
Author: liu_fei @lemon.com>
Date: Tue Jul 19 21:54:16 2016 +0800
fix fcc for gehua
#将patch打到master分支
root@liufei-VirtualBox:/home/liufei/learngit/abc# git am --ignore-whitespace --ignore-space-change patch/*.patch
Applying: add subtitle open & close api
Applying: fix hdmi&spdif audio control, add subtitle functions
/home/liufei/learngit/abc/.git/rebase-apply/patch:370: trailing whitespace.
ITI_S8 aLanguage[4]; // ISO_639_language_code type. such as: "CHN".
/home/liufei/learngit/abc/.git/rebase-apply/patch:873: trailing whitespace.
/home/liufei/learngit/abc/.git/rebase-apply/patch:973: trailing whitespace.
return result;
/home/liufei/learngit/abc/.git/rebase-apply/patch:975: new blank line at EOF.
+
warning: 4 lines add whitespace errors.
Applying: fix display zoom && subtitle bug
Applying: #31090, fix default audioChannel for topway
Applying: fix primer is the same with live
Applying: remove booking type from player
#查看打完patch之后的日志情况
root@liufei-VirtualBox:/home/liufei/learngit/abc# git log
commit 81f2eafcbf95f8b349183c0ef49c84395edefa6e
Author: lzy @lemon.com>
Date: Wed Jul 27 10:10:30 2016 +0800
remove booking type from player
commit c7dd5709753a6f839166c6d8752d9d08522f9cf8
Author: lzy @lemon.com>
Date: Tue Jul 26 18:00:38 2016 +0800
fix primer is the same with live
commit fd9c9795b294dc51d3d3519f47ca0b1e59a9f5bf
Author: lzy @lemon.com>
Date: Sat Jul 23 19:05:36 2016 +0800
#31090, fix default audioChannel for topway
commit 7e59503fe8783d1e076c0960b27e5dc5f3f7fce9
Author: lzy @lemon.com>
Date: Fri Jul 22 19:29:14 2016 +0800
fix display zoom && subtitle bug
commit 880885f2ca11543810fbbd627f8fa224e1f54e29
Author: lzy @lemon.com>
Date: Thu Jul 21 21:12:18 2016 +0800
fix hdmi&spdif audio control, add subtitle functions
commit c6aed80b84531fdf47a5a3a00b05b9dbc6d44b1d
Author: lzy @lemon.com>
Date: Thu Jul 21 19:59:42 2016 +0800
add subtitle open & close api
commit 8c39c8137e8265b35eb7c835ff30f7ac5db13f2f
Author: liu_fei @lemon.com>
Date: Tue Jul 19 21:54:16 2016 +0800
fix fcc for gehua