Git簡報
Transcript of Git簡報
GitTed
Agenda
Version Control Intro.
Git Flow
a successful git Model
Git Command Intro ( 主要)
reset/merge/rebase/cherry pick/stash/revert/diff
Version Control Intro.b4 version control
沒有歷史記錄不知道版本差別難以尋找更改的版本
Version Control Intro.多人共同開發
程式碼難以合併
Version Control Intro.
本地
集中式版控
SVN
分散式版控
Git
Version Control Intro.
server 儲存版本記錄,大家將變更 commit 到 server
if no connection …..
no history
no commit
集中式版控
Version Control Intro.
大家各自擁有記錄
如果 server 壞掉可使用 local 資料recovery
可以擁有 local branch
可在 local 端開發完成在 commit 至 server
開 branch 不用錢
no connection….
still has history list
分散式版控
Git Flow
git 開 branch 很方便,但是有沒有流程告訴大家如何管理 branch?
a successful git branching model
Git Flow
Git Flow
主要分支
master : 永遠處在 production ready
develop : 最新的下次發佈開發狀態
支援分支
feature : 開發新功能,從 develop 分支出來,完成後 merge 回 develop
Release : 準備 release 的版本,只修 bug ,從 develop 分支出來,完成後 merge回 master and develop
hotFix : 等不及 release 必須馬上修趕上線的情況,會從 master 分支出來,完成後merge 回 master 和 develop
Git Command Intro.
Git Command Intro.Branch Handle
• Merge / Rebase / Cherry Pick
Git Command Intro.
Merge
將兩條分支合併在一起
Rebase
將分支建立在 rebase 的節點上
https://bitbucket.org/Ted_Liang/merge_rebase
Rebase or Merge?
Git Command Intro.
在 branch 上完成了一個功能,該怎麼做?
Merge
Git Command Intro.
git merge master
Merge
Git Command Intro.
回到剛剛的情形
Rebase
Git Command Intro.
Git rebase master
Rebase
WTF?
Git Command Intro.Rebase
Git Command Intro.Rebase
When to use Rebase
想測試自己的功能在新版上是否正常 work
尚未 push
Git Command Intro.Rebase
Never 千萬不要對已經 push 的資料做 rebase
改變歷史記錄,會使已 pull 該 branch 的人遇到問題
Git Command Intro.Merge and Rebase
以下的 branch 爲 myFunction2 做了一次 rebase之後想要將 rebase 後的資料 merge 進 master
Git Command Intro.Merge and Rebase
直接 merge
merge —no-ff (no fast-ward)
Rebase 的其他用法
rebase -i SHA 重新整理 commit
Git Command Intro.Rebase
Git Command Intro.cherry pick
Git Command Intro.cherry pick
Git Command Intro.stash
假設我在 branch 做了資料修正,當我準備 push 時,發現線上有兩個 commit
不管他直接 pull
git stash -> pull -> stash apply
Git Command Intro.Revert
A
B
C
C’
錯誤的 push 時
錯誤的 merge 時
https://bitbucket.org/Ted_Liang/revert_reset
Git Command Intro.Revert
Delete remote hello
Reset to waaaa
Push again
send mail to everyone
Cant delete main branch
Git Command Intro.other
Revert 必須注意的事情
使用 revert 之後,假設之後想要把被 Revert 的 資料再度 merge 進去,不能使用merge( 並不會發生 merge 的動作 ) ,必須將 Revert 的資料再度 revert
Git Command Intro.Revert
版本比對vi ~/.gitconfig
設定 diffmerge
版本比對
git difftool --dir c5ab886 96a9dd5
Q&A
大家盡量問....我盡量答 XD