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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  14. 什什麼是 hunk ?

    View full-size slide

  15. 什什麼是 hunk ?

    View full-size slide

  16. 什什麼是 hunk ?

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  25. 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 full-size slide

  26. 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 full-size slide

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

    View full-size slide

  28. 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 full-size slide

  29. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  32. 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 full-size slide

  33. 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 full-size slide

  34. 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 full-size slide

  35. 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 full-size slide

  36. 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 full-size slide

  37. 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 full-size slide

  38. 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 full-size slide

  39. 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 full-size slide

  40. 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 full-size slide

  41. 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 full-size slide

  42. 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 full-size slide

  43. 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 full-size slide

  44. 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 full-size slide

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

    View full-size slide

  46. 發佈到遠端 git server

    View full-size slide

  47. 發佈到遠端 git server

    View full-size slide

  48. 發佈到遠端 git server

    View full-size slide

  49. git remote add origin git@git..
    Local
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B

    View full-size slide

  50. git remote add origin git@git..
    Local Remote
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B

    View full-size slide

  51. git remote add origin git@git..
    Local Remote
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B

    View full-size slide

  52. git remote add origin git@git..
    Local Remote
    Remote Repo/
    Master
    Remote Repo/
    Master
    Local Repo/
    Master
    Staging
    Area
    Workspace
    HASH C
    HASH A
    HASH B

    View full-size slide

  53. git remote add origin git@git..

    View full-size slide

  54. git remote add origin git@git..

    View full-size slide

  55. 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 full-size slide

  56. 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 full-size slide

  57. 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 full-size slide

  58. 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 full-size slide

  59. git push -u origin master

    View full-size slide

  60. git push -u origin master

    View full-size slide

  61. 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 full-size slide

  62. 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 full-size slide

  63. 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 full-size slide

  64. 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 full-size slide

  65. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  69. 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 full-size slide

  70. 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 full-size slide

  71. 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 full-size slide

  72. 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 full-size slide

  73. 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 full-size slide

  74. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  81. git merge []

    View full-size slide

  82. git merge []

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  94. git rebase develop

    View full-size slide

  95. git rebase develop

    View full-size slide

  96. git rebase develop

    View full-size slide

  97. git rebase develop

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  109. git merge with remote

    View full-size slide

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

    View full-size slide

  111. 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 full-size slide

  112. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  116. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  122. 使⽤用 除錯

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide