14. 14
合併 (Merge): 第一種 fast forward
A B
master branch 1
C
master 所指的 commit 在 branch 1 的路徑上,所以直接把
master 往前移至 branch 1 的位置
15. 15
在 branch 上修改檔案
A B C
master
branch 1
D
E F
master
branch 1
A B C DA
A B C EA F
16. 16
合併 (Merge): 第二種 三方合併 (Three Way Merge)
A B C D
E F
D
master
branch 1
以共同祖先 C 做為合併的參考點,合併 branch 1 到 master
注意,被合併的是 master ,所以 branch 1 不移動
17. 17
合併 (Merge): 第三種 rebase
A B C
master
branch 1
D
E' F'
master
branch 1
A B C DA
A B C E'A F'
原本 branch 1 是從 C 開始分支出去, rebase 可以重建分支時
的 commit ,並自動重新 commit 及套用已修改的部分
D
這 樣 可 以 讓
branch 1 透過
rebase 套 用
master 已 修 改
後的 D
25. 25
Git 參考流程 (Client 端 ) 建立 Branch
A B
master
A B
master
Server
Client
branch
26. 26
Git 參考流程 (Client 端 )
A B
master
A B
master
Server
Client
branch
CD
SC
Server 有其它人 commit SC
Client 也在 branch 上改 code
Client 讓 master 與
Server 同步,並在
branch 進行修改
27. 27
Git 參考流程 (Client 端 )
A B
master
A B
master
Server
Client
branch
CD
SC
Client 把 Server 上的
master 合併 到它的
master 保持同步
SC
Pull
(Fetch + Merge)
28. 28
Git 參考流程 (Client 端 )
A B
master
A B
master
Server
Client
branch
CC
SC
因為 master 上修改的
東西 branch 也要用到,
所以 client 決定把
master 合併到 branch
SC
CD
這是三方合併法
master 依然在 SC 不變
29. 29
Git 參考流程 (Client 端 )
A B
master
A B
master
Server
Client
branch
CC
SC
branch 修改完成後,合
併回 master
SC
CD CE
CF
30. 30
Git 參考流程 (Client 端 )
A B
master
A B
master
Server
Client
branch
CC
SC
SC
CD CE
SD
Server 上又有人 commit 了
CF
31. 31
Git 參考流程 (Client 端 )
A B
master
Server
Client
branch
CC
SC
CD CE
CF
A B
master
SC
SD
CD CE
CF
SE
Client 把其 master
合併到 Server 的
master
Push
38. 38
加入檔案
$touch README # 建立 README 檔
$git status # 透過 git status 查詢檔案狀態
On branch master
Initial commit
Untracked files: # 列出不受追蹤的檔案
(use "git add <file>..." to include in what will be committed)
README
nothing added to commit but untracked files present (use "git add" to track)
$git add README # 加入 README 檔
$git status # 透過 git status 查詢檔案狀態
On branch master
Initial commit
Changes to be committed: # 還沒有 commit 的檔案
(use "git rm --cached <file>..." to unstage)
new file: README
45. 45
標籤
git tag <label> 新增標籤
git tag <label> <SHA1> 在特定 commit 新增標籤
git tag <label> -m "message" 新增標籤,並附上訊息
git tag -d <label> 刪除標籤
git tag 顯示所有標籤
指令
$git tag
$git tag "v1.0"
$git tag "v0.1" 5bf61c204d
$git tag
v0.1
v1.0
$git tag -d "v1.0"
Deleted tag 'v1.0' (was a737846)
$git tag
v0.1
$git tag "v0.0" 5bf61c204d -m "first tag"
$git tag
v0.0
v0.1
51. 51
Branch 的合併 ( 三方合併 )
$git checkout -b feature-B
$touch feature-B.txt
$git add .
$git commit -m "feature B"
$git checkout master
$touch bugfix
$git add .
$git commit -m "bug fix"
$git merge feature-B
Merge made by the 'recursive' strategy.
feature-B.txt | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 feature-B.txt
A B C
master
feature-B
合併
D
A B C
master
feature-B
D
D
bugfi
x
feature-B.txt
bugfix
feature-B.txt
52. 52
Branch 的合併 (rebase)
$git checkout -b feature-C
Switched to a new branch 'feature-C'
$touch feature-c.txt
$git add .
$git commit -m "feature c"
$git checkout master
$touch bugfix
$git add .
$git commit -m "bug fix"
$git checkout feature-C
$git rebase master
First, rewinding head to replay your work on top of it...
Applying: feature c
A B C
master
feature-B
合併
Dfeature-C.txt
bugfix
A B C
master
feature-B
D'
feature-B.txt
透過 rebase 的方式合併,
可以讓各 branch 的有向循
環圖更乾淨
bugfix