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

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

Ab628671841774343b1020f22f712069?s=47 mouson
January 10, 2017

 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 的使用情境。

Ab628671841774343b1020f22f712069?s=128

mouson

January 10, 2017
Tweet

Transcript

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

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

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

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

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

    (陳佑⽵竹)
  6. 設定 git 環境 - git init Client (mouson)

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

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

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

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

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

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

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

    add git commit
  14. git add -p

  15. git add -p

  16. git add -p

  17. git add -p

  18. 什什麼是 hunk ?

  19. 什什麼是 hunk ?

  20. 什什麼是 hunk ?

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

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

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

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

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

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

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

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

    Area Workspace git add Hunk A HASH A Hunk D Hunk B Hunk C
  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
  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
  31. git add & commit 組合技 Local Local Repo/ Master Staging

    Area Workspace Hunk A HASH A Hunk D Hunk B Hunk C HASH B
  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
  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
  34. Demo

  35. Recap • ⼀一個 hash 代表⼀一次 change • ⼀一個 change 可以包含多個

    hunk • ⼀一個 hunk 最⼩小單位是 ⼀一⾏行行
  36. git HEAD Local Local Repo/ Master Staging Area Workspace Hunk

    A HASH A Hunk B Hunk C HASH B Hunk D HASH C
  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
  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^
  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^^
  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
  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
  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
  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
  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^
  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
  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
  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^
  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^
  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^
  50. git reset […] 重置 Local Local Repo/ Master Staging Area

    Workspace —mixed HEAD^ git reset —hard HEAD^ —soft HEAD^
  51. 發佈到遠端 git server

  52. 發佈到遠端 git server

  53. 發佈到遠端 git server

  54. git remote add origin git@git.. Local Local Repo/ Master Staging

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

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

    Local Repo/ Master Staging Area Workspace HASH C HASH A HASH B
  57. 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
  58. git remote add origin git@git..

  59. git remote add origin git@git..

  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
  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
  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
  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
  64. git push -u origin master

  65. git push -u origin master

  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
  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
  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
  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
  70. GIT BRANCH

  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
  72. git branch Local Remote Local Repo/ Master HASH C HASH

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

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

    HASH C HASH A HASH B git branch develop
  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
  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
  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
  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
  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)
  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)
  81. Local git checkout -b [name] A B C Master (HEAD)

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

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

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

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

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

    (HEAD) D
  87. git merge []

  88. git merge []

  89. Local git merge develop --no-ff A B C Develop Master

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

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

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

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

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

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

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

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

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

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

    D E G F 只能進⾏行行 no-ff
  100. git rebase develop

  101. git rebase develop

  102. git rebase develop

  103. git rebase develop

  104. Local git rebase develop A B C Develop Master (HEAD)

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

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

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

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

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

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

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

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

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

    D E F F' 重新計算差異異 G base G'
  114. 互動調整 git rebase -i (--interactive)

  115. git merge with remote

  116. git clone Local Remote Remote Repo/ Master Remote Repo/ Master

    Local Repo/ Master Staging Area Workspace git clone
  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
  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
  119. git pull Local Remote Remote Repo/ Master Remote Repo/ Master

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

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

    Master Local Repo/ Master Staging Area Workspace git fetch git rebase
  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
  123. mouson 從沒有 管控到 陳佑⽵竹 取得變更更的檔案 期間發⽣生些什什麼事?

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

    (陳佑⽵竹)
  125. 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
  126. 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
  127. 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....
  128. Recap

  129. None
  130. 使⽤用 除錯

  131. v2.3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    ? ? HEAD BAD BAD BAD GOOD GOOD X
  146. Demo https://github.com/mouson/20170110-demo-bisect

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