Git 학습 및 훈련

18813 단어 shellgit.
gitlab 에 서 는 누구나 fork 원 격 으로 자신의 디 렉 터 리 에 갈 라 놓 은 다음 자신의 디 렉 터 리 에서 개발 하고 코드 를 원 격 창고 에 업로드 한 다음 gitlab 서버 를 통 해 merge request 를 시작 하여 메 인 창고 에 동기 화 해 야 합 니 다.git 관련 조작 을 빨리 파악 하기 위해 훈련 을 설정 합 니 다. 다음 과 같 습 니 다.
원 격 창 고 를 player 로 가정 합 니 다.oop, 로 컬 복제 후 myplayer_oop, 원 격 창 고 는 로 컬 업데이트 보다 원 격 코드 를 로 컬 로 동기 화 해 야 합 니 다. 여 기 는 git pull 방식 을 사용 하지 않 고 다음 과 같은 방법 을 사용 합 니 다. 아래 명령 을 점차적으로 사용 하 는 것 이 목적 입 니 다.
  • 원 격 분기 git remote add 증가
  • 원 격 코드 git fetch 동기 화
  • git branch 사용
  • git format-patch
  • git apply 사용
  • git am 사용
  • git st
  • git log
  • git push

  • 다음은 실제 조작 과정 이다.
    #查看当前目录文件
    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
    
    

    좋은 웹페이지 즐겨찾기