SlideShare une entreprise Scribd logo
1  sur  29
GIT 原理与实战
—— 钱升钱研发流程管理规范
by Charles
目录
• Git 原理
• Git 实战
• Git 难点:merge 与 rebase
• Git 工作流
• 钱升钱研发管理规范
GIT 原理:CVCS中央版本控制系统
版本库
Version 3
Version 2
Version 1
远程服务器
File
本地计算机 A
File
Subversion
本地计算机 B
GIT 原理:DVCS分布式版本控制系统
Version 3
Version 2
Version 1
File
计算机 B
Version 3
Version 2
Version 1
File
计算机 A
Version 3
Version 2
Version 1
File
计算机 C
Git
版本库
版本库版本库
checkout & commit
checkout & commit
checkout & commit
pull & push
GIT 原理:文件可以处于三种境况
工作目录 暂存区 .git 版本库
checkout 代码
暂存修改
commit 代码
GIT 原理:文件的四种状态流转图
Untracked Unmodified Modified
移除(rm)
修改
暂存(add)
Staged
添加(add)
提交(commit)
GIT 原理:数据流和存储
远程版本库
本地版本库
工作目录
暂存区
commit
add
checkout
fetch pushpull
GIT 原理:GIT的实质是文件系统
“version 1”
83baae
“version 2”
1f7a7a
“new file”
fa49b0
tree
d8329f
tree
0155eb
tree
3c4e9c
commit 1
fdf4fc
commit 2
cac0ca
commit 3
1a410e
refs/heads/master
refs/heads/test
test.txt
test.txt
test.txt
new.txt
new.txt
bak
文件对象树对象提交对象引用
GIT 实战:使用GIT的一般任务
• 克隆一个版本库 git clone
• 创建一个分支 git branch
• 修改并检查文件状态 git status
• 保存修改 git add & git commit
• 整合代码 git merge
• 同步远程修改 git pull & git fetch
• 推送代码到远程 git push
GIT 实战:克隆一个版本库
• 命令行:
• git clone user@git.server.com:path/to/repo.git local_rename
• 支持的协议:
• HTTP/HTTPS/SSH/Git 等等
• 窍门:
• git clone --depth=10
• 鉴权:
• 公钥/私钥对
• 用户名/密码
GIT 实战:创建一个分支
• 命令行:
• git branch devel
• git checkout devel
• Or … just
• git checkout -b devel
• git branch -D devel
GIT 实战:修改并检查文件状态
• 命令行:
• git status
• git diff
GIT 实战:保存修改
• 命令行:
• git commit
• git commit -a
• git commit --amend
• git commit -m
• GIT_EDITOR
• EDITOR
GIT 实战:整合代码
• 命令行:
• git merge
• git merge --no-ff
GIT 实战:同步远程代码
• 命令行:
• git fetch
• git pull
• git pull --no-ff
GIT 实战:推送代码到远程
• 命令行:
• git push
• git push origin master
• git push origin dev:dev
• git push origin :testing
GIT 难点:MERGE 快进
C1 C2 C3 B1 B2
master
branch
merge (in fast forward way)
git checkout master
git merge branch
GIT 难点:MERGE 合并
C1 C2 C3 B1 B2
master
branch
git merge branch
C4 C5
C6
GIT 难点:REBASE 基址重算
C1 C2 C3 B1 B2
master
branch
git checkout branch
git rebase master
C4 C5
B1’ B2’
git checkout master
git merge branch
merge (in fast forward way)
GIT 工作流:什么是工作流
• 工作流就是工作方式和顺序
• 在多个人时候,就是协作方式
• 其内涵是分支定义和管理模型
• 其实质是一套规则和方法论
GIT 工作流:最流行的
http://nvie.com/posts/a-successful-git-
branching-model/
http://www.ruanyifeng.com/blog/2
012/07/git.html (翻译)
GIT 工作流:钱升钱的master
feature
v1.1.1
v1.1.2
v1.1.3
tags
v1.1.5
hotfix
v1.1.4
sync 是一种日常
任务,也使用
merge指令,不要
使用rebase指令
钱升钱研发流程管理规范
• 程序员在“特性分支”上开发功能
• 开发完毕后,“特性分支”提交测试
• 测试完毕后,程序员将“特性分支”合并到“主干”
• 测试在“主干”上进行集成测试和回归
• 程序员在“主干”上修复集成测试的缺陷
• 测试完毕后,测试员给“主干”打 tag
• 测试员发布 tag 到生产环境
合作中遇到的问题
• 支撑同一个 App 版本的 API 不应在两个特性分支上
• 两个特性同期发布时,要引入新分支进行特性兼容测试
• 短期内不应重复使用同名分支做特性开发
GIT乐趣小窍门
• 铁律:推送到远程的东西不要修改
GIT乐趣小窍门
• zsh 的 git 插件带来的 alias
GIT乐趣小窍门
• 在本地美化你的 commit
GIT乐趣小窍门
• 如何产生线性的 commit history
GIT乐趣小窍门
• rebase 大师

Contenu connexe

Tendances

Learn git
Learn gitLearn git
Learn git甘 李
 
幸福快樂的完美結局
幸福快樂的完美結局幸福快樂的完美結局
幸福快樂的完美結局Anna Su
 
Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)Cloud Tu
 
工程師必備第一工具 - Git
工程師必備第一工具 - Git工程師必備第一工具 - Git
工程師必備第一工具 - GitAlan Tsai
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍medcl
 
Git 入門與實作
Git 入門與實作Git 入門與實作
Git 入門與實作奕浦 郭
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學littlebtc
 
Git and git hub
Git and git hubGit and git hub
Git and git hub唯 李
 
Android 程式設計(4)
Android 程式設計(4)Android 程式設計(4)
Android 程式設計(4)Roy Wang
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
Jenkins x GitLab CI
Jenkins x GitLab CIJenkins x GitLab CI
Jenkins x GitLab CIYihsuan Chen
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包Chen-Ming Yang
 
git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學Doremi Lin
 
[China merge world tour] Perforce Introducing Git Fusion
[China   merge world tour] Perforce Introducing Git Fusion[China   merge world tour] Perforce Introducing Git Fusion
[China merge world tour] Perforce Introducing Git FusionPerforce
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學hydai
 
Git & git hub v1.2
Git & git hub v1.2Git & git hub v1.2
Git & git hub v1.2Chris Chen
 

Tendances (20)

Git 实战
Git 实战Git 实战
Git 实战
 
Learn git
Learn gitLearn git
Learn git
 
幸福快樂的完美結局
幸福快樂的完美結局幸福快樂的完美結局
幸福快樂的完美結局
 
Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)Git tutorial for windows user (給 Windows user 的 Git 教學)
Git tutorial for windows user (給 Windows user 的 Git 教學)
 
工程師必備第一工具 - Git
工程師必備第一工具 - Git工程師必備第一工具 - Git
工程師必備第一工具 - Git
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍
 
Git 入門與實作
Git 入門與實作Git 入門與實作
Git 入門與實作
 
Git 版本控制 (使用教學)
Git 版本控制 (使用教學)Git 版本控制 (使用教學)
Git 版本控制 (使用教學)
 
Git教學
Git教學Git教學
Git教學
 
Git Tutorial 教學
Git Tutorial 教學Git Tutorial 教學
Git Tutorial 教學
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Android 程式設計(4)
Android 程式設計(4)Android 程式設計(4)
Android 程式設計(4)
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
Jenkins x GitLab CI
Jenkins x GitLab CIJenkins x GitLab CI
Jenkins x GitLab CI
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包
 
git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學git, repo, Gerrit 基礎教學
git, repo, Gerrit 基礎教學
 
[China merge world tour] Perforce Introducing Git Fusion
[China   merge world tour] Perforce Introducing Git Fusion[China   merge world tour] Perforce Introducing Git Fusion
[China merge world tour] Perforce Introducing Git Fusion
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學
 
Git & git hub v1.2
Git & git hub v1.2Git & git hub v1.2
Git & git hub v1.2
 

Similaire à Git原理与实战 201607

Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)flylon
 
Git introduction
Git introductionGit introduction
Git introductionmythnc
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshellNelson Tai
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to gitBo-Yi Wu
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報Bachue Zhou
 
Git & git flow
Git & git flowGit & git flow
Git & git flowAmo Wu
 
Git Flow 管理
Git Flow 管理Git Flow 管理
Git Flow 管理Pu Lee
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence TutorialHo Kim
 
Git使用进阶
Git使用进阶Git使用进阶
Git使用进阶Han Qin
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Wen-Tien Chang
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作Bo-Yi Wu
 
Git使用入门
Git使用入门Git使用入门
Git使用入门dpf2e
 
Submodule && subtree
Submodule && subtreeSubmodule && subtree
Submodule && subtree哲 于
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgitRhythm Sun
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upWen-Tien Chang
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用Philip Zheng
 

Similaire à Git原理与实战 201607 (20)

Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git 教學
Git 教學Git 教學
Git 教學
 
COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報COSCUP 2015 開源之道-Git工作坊教學簡報
COSCUP 2015 開源之道-Git工作坊教學簡報
 
Git & git flow
Git & git flowGit & git flow
Git & git flow
 
Git Flow 管理
Git Flow 管理Git Flow 管理
Git Flow 管理
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence Tutorial
 
Git使用进阶
Git使用进阶Git使用进阶
Git使用进阶
 
Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀Git 版本控制系統 -- 從微觀到宏觀
Git 版本控制系統 -- 從微觀到宏觀
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作
 
Git share
Git shareGit share
Git share
 
Git使用入门
Git使用入门Git使用入门
Git使用入门
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
Git
GitGit
Git
 
Submodule && subtree
Submodule && subtreeSubmodule && subtree
Submodule && subtree
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgit
 
Yet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom upYet another introduction to Git - from the bottom up
Yet another introduction to Git - from the bottom up
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用
 

Git原理与实战 201607