Git簡報

36
Git Ted

Transcript of Git簡報

Page 1: Git簡報

GitTed

Page 2: Git簡報

Agenda

Version Control Intro.

Git Flow

a successful git Model

Git Command Intro ( 主要)

reset/merge/rebase/cherry pick/stash/revert/diff

Page 3: Git簡報

Version Control Intro.b4 version control

沒有歷史記錄不知道版本差別難以尋找更改的版本

Page 4: Git簡報

Version Control Intro.多人共同開發

程式碼難以合併

Page 5: Git簡報

Version Control Intro.

本地

集中式版控

SVN

分散式版控

Git

Page 6: Git簡報

Version Control Intro.

server 儲存版本記錄,大家將變更 commit 到 server

if no connection …..

no history

no commit

集中式版控

Page 7: Git簡報

Version Control Intro.

大家各自擁有記錄

如果 server 壞掉可使用 local 資料recovery

可以擁有 local branch

可在 local 端開發完成在 commit 至 server

開 branch 不用錢

no connection….

still has history list

分散式版控

Page 8: Git簡報

Git Flow

git 開 branch 很方便,但是有沒有流程告訴大家如何管理 branch?

a successful git branching model

Page 9: Git簡報

Git Flow

Page 10: Git簡報
Page 11: Git簡報

Git Flow

主要分支

master : 永遠處在 production ready

develop : 最新的下次發佈開發狀態

支援分支

feature : 開發新功能,從 develop 分支出來,完成後 merge 回 develop

Release : 準備 release 的版本,只修 bug ,從 develop 分支出來,完成後 merge回 master and develop

hotFix : 等不及 release 必須馬上修趕上線的情況,會從 master 分支出來,完成後merge 回 master 和 develop

Page 12: Git簡報

Git Command Intro.

Page 13: Git簡報

Git Command Intro.Branch Handle

• Merge / Rebase / Cherry Pick

Page 14: Git簡報

Git Command Intro.

Merge

將兩條分支合併在一起

Rebase

將分支建立在 rebase 的節點上

https://bitbucket.org/Ted_Liang/merge_rebase

Rebase or Merge?

Page 15: Git簡報

Git Command Intro.

在 branch 上完成了一個功能,該怎麼做?

Merge

Page 16: Git簡報

Git Command Intro.

git merge master

Merge

Page 17: Git簡報

Git Command Intro.

回到剛剛的情形

Rebase

Page 18: Git簡報

Git Command Intro.

Git rebase master

Rebase

Page 19: Git簡報

WTF?

Page 20: Git簡報

Git Command Intro.Rebase

Page 21: Git簡報

Git Command Intro.Rebase

When to use Rebase

想測試自己的功能在新版上是否正常 work

尚未 push

Page 22: Git簡報
Page 23: Git簡報

Git Command Intro.Rebase

Never 千萬不要對已經 push 的資料做 rebase

改變歷史記錄,會使已 pull 該 branch 的人遇到問題

Page 24: Git簡報

Git Command Intro.Merge and Rebase

以下的 branch 爲 myFunction2 做了一次 rebase之後想要將 rebase 後的資料 merge 進 master

Page 25: Git簡報

Git Command Intro.Merge and Rebase

直接 merge

merge —no-ff (no fast-ward)

Page 26: Git簡報

Rebase 的其他用法

rebase -i SHA 重新整理 commit

Git Command Intro.Rebase

Page 27: Git簡報

Git Command Intro.cherry pick

Page 28: Git簡報

Git Command Intro.cherry pick

Page 29: Git簡報

Git Command Intro.stash

假設我在 branch 做了資料修正,當我準備 push 時,發現線上有兩個 commit

不管他直接 pull

git stash -> pull -> stash apply

Page 30: Git簡報

Git Command Intro.Revert

A

B

C

C’

Page 31: Git簡報

錯誤的 push 時

錯誤的 merge 時

https://bitbucket.org/Ted_Liang/revert_reset

Git Command Intro.Revert

Page 32: Git簡報

Delete remote hello

Reset to waaaa

Push again

send mail to everyone

Cant delete main branch

Git Command Intro.other

Page 33: Git簡報

Revert 必須注意的事情

使用 revert 之後,假設之後想要把被 Revert 的 資料再度 merge 進去,不能使用merge( 並不會發生 merge 的動作 ) ,必須將 Revert 的資料再度 revert

Git Command Intro.Revert

Page 34: Git簡報

版本比對vi ~/.gitconfig

設定 diffmerge

Page 35: Git簡報

版本比對

git difftool --dir c5ab886 96a9dd5

Page 36: Git簡報

Q&A

大家盡量問....我盡量答 XD