Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GIT從入門到應用-線上讀書會

 GIT從入門到應用-線上讀書會

在線上讀書會所做的 GIT 分享,此次除了 git 的基礎教學外,也額外在增加關於如何最快找到出錯的 commit 的方法。使用 git bisect 來做二分法除錯。

發表於 2017 年 1 月 10 日 於 線上讀書會

相關錄影:https://www.youtube.com/watch?v=gVByWjwetVc
範例github 連結:https://github.com/mouson/20170110-demo-bisect

PS. 範例僅需要跟著 README 的內容也可以體驗一下 git bisect 的使用情境。

mouson(墨嗓)

January 10, 2017
Tweet

More Decks by mouson(墨嗓)

Other Decks in Technology

Transcript

  1. 陳佑⽵竹 Mouson
    2017.01.10 @ 線上讀書會
    從入⾨門
    到實務運⽤用

    View Slide

  2. 多⼈人協作從沒有 管控到
    合作者 取得變更更的檔案
    期間發⽣生些什什麼事?

    View Slide

  3. mouson 從沒有 管控到
    陳佑⽵竹 取得變更更的檔案
    期間發⽣生些什什麼事?

    View Slide

  4. mouson 上傳 Server 由 陳佑⽵竹 取得
    Client (mouson) Server Client (陳佑⽵竹)

    View Slide

  5. mouson 上傳 Server 由 陳佑⽵竹 取得
    Client (mouson) Server Client (陳佑⽵竹)

    View Slide

  6. 設定 git 環境 - git init
    Client (mouson)

    View Slide

  7. 設定 git 環境 - git init
    Client (mouson)

    View Slide

  8. 設定 git 環境 - git init
    Client (mouson)

    View Slide

  9. git 區域分類
    Client (mouson)
    Local Repo/
    Master
    Staging
    Area
    Workspace

    View Slide

  10. git status
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git status

    View Slide

  11. git status
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git status

    View Slide

  12. git add [folder/file] 新增
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add

    View Slide

  13. git commit
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add git commit

    View Slide

  14. git add -p

    View Slide

  15. git add -p

    View Slide

  16. git add -p

    View Slide

  17. git add -p

    View Slide

  18. 什什麼是 hunk ?

    View Slide

  19. 什什麼是 hunk ?

    View Slide

  20. 什什麼是 hunk ?

    View Slide

  21. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace

    View Slide

  22. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A

    View Slide

  23. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add
    Hunk A

    View Slide

  24. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add git commit
    Hunk A

    View Slide

  25. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add git commit
    Hunk A
    HASH A

    View Slide

  26. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A

    View Slide

  27. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A
    Hunk B
    Hunk C
    Hunk D

    View Slide

  28. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add
    Hunk A
    HASH A
    Hunk D
    Hunk B
    Hunk C

    View Slide

  29. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add git commit
    Hunk A
    HASH A
    Hunk D
    Hunk B
    Hunk C

    View Slide

  30. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add git commit
    Hunk A
    HASH A
    Hunk D
    Hunk B
    Hunk C
    HASH B

    View Slide

  31. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A
    Hunk D
    Hunk B
    Hunk C
    HASH B

    View Slide

  32. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    Hunk D

    View Slide

  33. git add & commit 組合技
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git add git commit
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    Hunk D
    HASH C

    View Slide

  34. Demo

    View Slide

  35. Recap
    • ⼀一個 hash 代表⼀一次 change
    • ⼀一個 change 可以包含多個 hunk
    • ⼀一個 hunk 最⼩小單位是 ⼀一⾏行行

    View Slide

  36. git HEAD
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    Hunk D
    HASH C

    View Slide

  37. git HEAD
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    Hunk D
    HASH C
    HEAD

    View Slide

  38. git HEAD
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    Hunk D
    HASH C
    HEAD
    HEAD^

    View Slide

  39. git HEAD
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    Hunk D
    HASH C
    HEAD
    HEAD^
    HEAD^^

    View Slide

  40. git reset --mixed 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk D
    HASH C
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B

    View Slide

  41. git reset --mixed 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    —mixed HEAD^
    Hunk D
    HASH C
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B

    View Slide

  42. git reset --mixed 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    —mixed HEAD^
    Hunk D
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B

    View Slide

  43. git reset --soft 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk D
    HASH C
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B

    View Slide

  44. git reset --soft 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk D
    HASH C
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    —soft HEAD^

    View Slide

  45. git reset --soft 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    —soft HEAD^
    Hunk D

    View Slide

  46. git reset --hard 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk D
    HASH C
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B

    View Slide

  47. git reset --hard 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk D
    HASH C
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    git reset —hard HEAD^

    View Slide

  48. git reset --hard 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk D
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    git reset —hard HEAD^

    View Slide

  49. git reset --hard 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    Hunk A
    HASH A
    Hunk B
    Hunk C
    HASH B
    git reset —hard HEAD^

    View Slide

  50. git reset […] 重置
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    —mixed HEAD^
    git reset —hard HEAD^
    —soft HEAD^

    View Slide

  51. 發佈到遠端 git server

    View Slide

  52. 發佈到遠端 git server

    View Slide

  53. 發佈到遠端 git server

    View Slide

  54. git remote add origin [email protected]
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B

    View Slide

  55. git remote add origin [email protected]
    Local Remote
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B

    View Slide

  56. git remote add origin [email protected]
    Local Remote
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B

    View Slide

  57. git remote add origin [email protected]
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B

    View Slide

  58. git remote add origin [email protected]

    View Slide

  59. git remote add origin [email protected]

    View Slide

  60. git push -u origin master
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B

    View Slide

  61. git push -u origin master
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git push
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B

    View Slide

  62. git push -u origin master
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git push
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B

    View Slide

  63. git push -u origin master
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git push
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B

    View Slide

  64. git push -u origin master

    View Slide

  65. git push -u origin master

    View Slide

  66. git fetch
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B

    View Slide

  67. git fetch
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B
    HASH D
    HASH C
    HASH A
    HASH B
    HASH D

    View Slide

  68. git fetch
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B
    git fetch
    HASH D
    HASH C
    HASH A
    HASH B
    HASH D

    View Slide

  69. git fetch
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B
    git fetch
    HASH C
    HASH A
    HASH B
    HASH D HASH D

    View Slide

  70. GIT BRANCH

    View Slide

  71. git branch
    Local Remote
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B
    Remote Repo/
    Master
    Remote Repo/
    Master
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B
    HASH D HASH D

    View Slide

  72. git branch
    Local Remote
    Local Repo/
    Master
    HASH C
    HASH A
    HASH B

    View Slide

  73. git branch
    Local Remote
    Local Repo/
    Master
    HASH C
    HASH A
    HASH B

    View Slide

  74. git branch
    Local Remote
    Local Repo/
    Master
    Local Repo/
    Develop
    HASH C
    HASH A
    HASH B
    git branch
    develop

    View Slide

  75. git branch
    Local Remote
    Local Repo/
    Master
    Local Repo/
    Develop
    HASH C
    HASH A
    HASH B
    git branch
    develop
    HASH C
    HASH A
    HASH B

    View Slide

  76. git branch
    Local Remote
    Local Repo/
    Master
    Local Repo/
    Develop
    HASH C
    HASH A
    HASH B
    git branch
    develop
    HASH C
    HASH A
    HASH B

    View Slide

  77. git branch
    Local Remote
    Local Repo/
    Master
    Local Repo/
    Develop
    HASH C
    HASH A
    HASH B
    git branch
    develop
    HASH C
    HASH A
    HASH B

    View Slide

  78. git branch
    Local Remote
    Local Repo/
    Master
    Local Repo/
    Develop
    HASH C
    HASH A
    HASH B
    git branch
    develop
    HASH C
    HASH A
    HASH B
    A B C

    View Slide

  79. git branch
    Local Remote
    Local Repo/
    Master
    Local Repo/
    Develop
    HASH C
    HASH A
    HASH B
    git branch
    develop
    HASH C
    HASH A
    HASH B
    A B C
    Master (HEAD)

    View Slide

  80. git branch
    Local Remote
    Local Repo/
    Master
    Local Repo/
    Develop
    HASH C
    HASH A
    HASH B
    git branch
    develop
    HASH C
    HASH A
    HASH B
    A B C
    Master
    Develop
    (HEAD)

    View Slide

  81. Local
    git checkout -b [name]
    A B C
    Master (HEAD)

    View Slide

  82. Local
    git checkout -b [name]
    A B C
    Master
    Develop
    (HEAD)

    View Slide

  83. Local
    git checkout -b [name]
    A B C
    Master
    Develop (HEAD)

    View Slide

  84. Local
    git checkout -b [name]
    A B C
    Master
    Develop (HEAD)

    View Slide

  85. Local
    git checkout -b [name]
    A B C
    Master
    Develop (HEAD)
    D

    View Slide

  86. Local
    git checkout -b [name]
    A B C
    Master
    Develop (HEAD)
    D

    View Slide

  87. git merge []

    View Slide

  88. git merge []

    View Slide

  89. Local
    git merge develop --no-ff
    A B C
    Develop
    Master (HEAD)
    D E

    View Slide

  90. Local
    git merge develop --no-ff
    A B C
    Develop
    Master (HEAD)
    D E
    F

    View Slide

  91. Local
    git merge develop --no-ff
    A B C
    Develop
    Master (HEAD)
    D E
    F

    View Slide

  92. Local
    git merge develop --ff (fast-forward)
    A B C
    Develop
    Master (HEAD)
    D E

    View Slide

  93. Local
    git merge develop --ff (fast-forward)
    A B C
    Develop
    Master (HEAD)
    D E

    View Slide

  94. Local
    git merge develop
    A B C
    Develop
    Master (HEAD)
    D

    View Slide

  95. Local
    git merge develop
    A B C
    Develop
    Master (HEAD)
    D

    View Slide

  96. Local
    git merge develop
    A B C
    Develop
    Master (HEAD)
    D E
    F

    View Slide

  97. Local
    git merge develop
    A B C
    Develop
    Master (HEAD)
    D E
    G
    F

    View Slide

  98. Local
    git merge develop
    A B C
    Develop
    Master (HEAD)
    D E
    G
    F

    View Slide

  99. Local
    git merge develop
    A B C
    Develop
    Master (HEAD)
    D E
    G
    F
    只能進⾏行行 no-ff

    View Slide

  100. git rebase develop

    View Slide

  101. git rebase develop

    View Slide

  102. git rebase develop

    View Slide

  103. git rebase develop

    View Slide

  104. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F
    base
    G

    View Slide

  105. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F G
    base

    View Slide

  106. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F G
    base

    View Slide

  107. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F
    重新計算差異異
    G
    base

    View Slide

  108. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F
    F'
    重新計算差異異
    G
    base

    View Slide

  109. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F
    F'
    重新計算差異異
    G
    base

    View Slide

  110. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F
    F'
    重新計算差異異
    G
    base

    View Slide

  111. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F
    F'
    重新計算差異異
    G
    base G'

    View Slide

  112. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F
    F'
    重新計算差異異
    G
    base G'

    View Slide

  113. Local
    git rebase develop
    A B C
    Develop
    Master (HEAD)
    D E
    F
    F'
    重新計算差異異
    G
    base G'

    View Slide

  114. 互動調整
    git rebase -i
    (--interactive)

    View Slide

  115. git merge with remote

    View Slide

  116. git clone
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git clone

    View Slide

  117. git merge
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B
    git fetch
    HASH D
    HASH C
    HASH A
    HASH B
    HASH D HASH D
    HASH D

    View Slide

  118. git merge
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B
    HASH C
    HASH A
    HASH B
    git fetch
    HASH D
    HASH C
    HASH A
    HASH B
    HASH D HASH D
    git merge
    HASH D HASH D

    View Slide

  119. git pull
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git fetch
    git merge

    View Slide

  120. git pull
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git fetch
    git merge
    git pull

    View Slide

  121. git pull --rebase
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git fetch
    git rebase

    View Slide

  122. git pull --rebase
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    git fetch
    git rebase
    git pull --rebase

    View Slide

  123. mouson 從沒有 管控到
    陳佑⽵竹 取得變更更的檔案
    期間發⽣生些什什麼事?

    View Slide

  124. mouson 上傳 Server 由 陳佑⽵竹 取得
    Client (mouson) Server Client (陳佑⽵竹)

    View Slide

  125. mouson 上傳 Server 由 陳佑⽵竹 取得
    Client (mouson) Server Client (陳佑⽵竹)
    1. git init
    2. git add .
    3. git commit
    4. git remote add
    origin [email protected]
    5. git push -u origin
    master

    View Slide

  126. mouson 上傳 Server 由 陳佑⽵竹 取得
    Client (mouson) Server Client (陳佑⽵竹)
    1. git init
    2. git add .
    3. git commit
    4. git remote add
    origin [email protected]
    5. git push -u origin
    master

    View Slide

  127. mouson 上傳 Server 由 陳佑⽵竹 取得
    Client (mouson) Server Client (陳佑⽵竹)
    1. git init
    2. git add .
    3. git commit
    4. git remote add
    origin [email protected]
    5. git push -u origin
    master
    1. git clone [email protected]

    View Slide

  128. Recap

    View Slide

  129. View Slide

  130. 使⽤用 除錯

    View Slide

  131. v2.3

    View Slide

  132. ? ? ? ? ? ? ? HEAD
    merge 後功能壞掉了了
    v2.3

    View Slide

  133. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? ? ? ? ? HEAD

    View Slide

  134. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? ? ? ? ? HEAD

    View Slide

  135. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? ? ? ? ? HEAD
    BAD

    View Slide

  136. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD

    View Slide

  137. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD

    View Slide

  138. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD

    View Slide

  139. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD

    View Slide

  140. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD
    GOOD

    View Slide

  141. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD
    GOOD

    View Slide

  142. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD
    GOOD
    GOOD

    View Slide

  143. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD
    GOOD
    GOOD

    View Slide

  144. ⽤用 git bisect ⼆二分法查錯
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD
    GOOD
    GOOD X

    View Slide

  145. ⽤用 git blame 找出兇⼿手
    v2.3 ? ? ? BAD ? ? ? HEAD
    BAD BAD
    BAD
    GOOD
    GOOD X

    View Slide

  146. Demo
    https://github.com/mouson/20170110-demo-bisect

    View Slide

  147. Q & A
    陳佑⽵竹 Mouson
    https://facebook.com/mouson

    View Slide