Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You

304 views

Published on

Git is a powerful, critical, yet poorly understood tool that virtually all Open Source developers use. One of the key features that git provides is a powerful and comprehensive log that displays the history of all the changes that have happened in a project, including potential developments that weren't ever merged, details about former versions of software that can inform future development, and even such mundane details as whether development on feature A started before or after development of bugfix B.

Despite the power and utility of git's log, few developers take full advantage of it. Worse, some common practices that developers have adopted in the name of convenience (or just plain cargo culting) can actually destroy this useful information. Moreover, if developers are following the common exhortation to "commit often", they may end up with logs full of uninteresting noise, as all the details of debugging attempts and experiments are inadvertently recorded.

This talk will:

* detail the potential benefits of having informative and well structured logs
* discuss common developer habits that can make logs less useful
* explain techniques to preserve informative development history

Published in: Software
  • Be the first to comment

  • Be the first to like this

Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You

  1. 1. logs are magic! john sj anderson | @genehack | !seagl 2017 Logs Are MAGIC — SeaGL 2017 — @genehack 1
  2. 2. why git workflows & commit structure should matter to you john sj anderson | @genehack | !seagl 2017 Logs Are MAGIC — SeaGL 2017 — @genehack 2
  3. 3. hi, i’m john. a/k/a @genehack Logs Are MAGIC — SeaGL 2017 — @genehack 3
  4. 4. vp, technology infinity interactive Logs Are MAGIC — SeaGL 2017 — @genehack 4
  5. 5. i ❤❤❤❤ revision controlLogs Are MAGIC — SeaGL 2017 — @genehack 5
  6. 6. cvsLogs Are MAGIC — SeaGL 2017 — @genehack 6
  7. 7. svnLogs Are MAGIC — SeaGL 2017 — @genehack 7
  8. 8. rcsLogs Are MAGIC — SeaGL 2017 — @genehack 8
  9. 9. rcsLogs Are MAGIC — SeaGL 2017 — @genehack 9
  10. 10. gitLogs Are MAGIC — SeaGL 2017 — @genehack 10
  11. 11. i ❤ git Logs Are MAGIC — SeaGL 2017 — @genehack 11
  12. 12. quick poll! Logs Are MAGIC — SeaGL 2017 — @genehack 12
  13. 13. what this talk isn’tLogs Are MAGIC — SeaGL 2017 — @genehack 13
  14. 14. no universal truthsLogs Are MAGIC — SeaGL 2017 — @genehack 14
  15. 15. not even “best practices” Logs Are MAGIC — SeaGL 2017 — @genehack 15
  16. 16. what this talk isLogs Are MAGIC — SeaGL 2017 — @genehack 16
  17. 17. some opinions Logs Are MAGIC — SeaGL 2017 — @genehack 17
  18. 18. backed up with experience Logs Are MAGIC — SeaGL 2017 — @genehack 18
  19. 19. maybe more important for larger projects Logs Are MAGIC — SeaGL 2017 — @genehack 19
  20. 20. but also good for projects that aspire to be biggerLogs Are MAGIC — SeaGL 2017 — @genehack 20
  21. 21. maybe more relevant for coding projects Logs Are MAGIC — SeaGL 2017 — @genehack 21
  22. 22. but also applicable for doc or config repos Logs Are MAGIC — SeaGL 2017 — @genehack 22
  23. 23. making better use of history Logs Are MAGIC — SeaGL 2017 — @genehack 23
  24. 24. making better history Logs Are MAGIC — SeaGL 2017 — @genehack 24
  25. 25. prerequisites Logs Are MAGIC — SeaGL 2017 — @genehack 25
  26. 26. consistency Logs Are MAGIC — SeaGL 2017 — @genehack 26
  27. 27. habits Logs Are MAGIC — SeaGL 2017 — @genehack 27
  28. 28. do it all the timeLogs Are MAGIC — SeaGL 2017 — @genehack 28
  29. 29. then you don’t have to think about itLogs Are MAGIC — SeaGL 2017 — @genehack 29
  30. 30. even betterLogs Are MAGIC — SeaGL 2017 — @genehack 30
  31. 31. automate itLogs Are MAGIC — SeaGL 2017 — @genehack 31
  32. 32. how to make better history Logs Are MAGIC — SeaGL 2017 — @genehack 32
  33. 33. workflows Logs Are MAGIC — SeaGL 2017 — @genehack 33
  34. 34. no remote no branches master only Logs Are MAGIC — SeaGL 2017 — @genehack 34
  35. 35. local master no branches & periodic pushes Logs Are MAGIC — SeaGL 2017 — @genehack 35
  36. 36. git flow Logs Are MAGIC — SeaGL 2017 — @genehack 36
  37. 37. some notable antipatterns Logs Are MAGIC — SeaGL 2017 — @genehack 37
  38. 38. squashed branches Logs Are MAGIC — SeaGL 2017 — @genehack 38
  39. 39. fast forward merges Logs Are MAGIC — SeaGL 2017 — @genehack 39
  40. 40. rebase before merge Logs Are MAGIC — SeaGL 2017 — @genehack 40
  41. 41. all destroy history Logs Are MAGIC — SeaGL 2017 — @genehack 41
  42. 42. all destroy history needlessly Logs Are MAGIC — SeaGL 2017 — @genehack 42
  43. 43. linear commit history is a lieLogs Are MAGIC — SeaGL 2017 — @genehack 43
  44. 44. linear commit history is a lie (probably) Logs Are MAGIC — SeaGL 2017 — @genehack 44
  45. 45. instead Logs Are MAGIC — SeaGL 2017 — @genehack 45
  46. 46. some good patternsLogs Are MAGIC — SeaGL 2017 — @genehack 46
  47. 47. branch Logs Are MAGIC — SeaGL 2017 — @genehack 47
  48. 48. branch for errythang Logs Are MAGIC — SeaGL 2017 — @genehack 48
  49. 49. (specifics will vary) Logs Are MAGIC — SeaGL 2017 — @genehack 49
  50. 50. have a release branchLogs Are MAGIC — SeaGL 2017 — @genehack 50
  51. 51. release may be master release may be another branch Logs Are MAGIC — SeaGL 2017 — @genehack 51
  52. 52. (again, specifics will vary) Logs Are MAGIC — SeaGL 2017 — @genehack 52
  53. 53. merging to the release branch is a releaseLogs Are MAGIC — SeaGL 2017 — @genehack 53
  54. 54. (ideally, automatically) Logs Are MAGIC — SeaGL 2017 — @genehack 54
  55. 55. make all merges non-ffLogs Are MAGIC — SeaGL 2017 — @genehack 55
  56. 56. an asideLogs Are MAGIC — SeaGL 2017 — @genehack 56
  57. 57. ~/.gitconfig Logs Are MAGIC — SeaGL 2017 — @genehack 57
  58. 58. git config --global merge.ff false git config --global pull.ff only Logs Are MAGIC — SeaGL 2017 — @genehack 58
  59. 59. [merge] ff = false [pull] ff = only Logs Are MAGIC — SeaGL 2017 — @genehack 59
  60. 60. maximal historical informationLogs Are MAGIC — SeaGL 2017 — @genehack 60
  61. 61. keep it cleanLogs Are MAGIC — SeaGL 2017 — @genehack 61
  62. 62. another asideLogs Are MAGIC — SeaGL 2017 — @genehack 62
  63. 63. ~/.gitconfig aliasesLogs Are MAGIC — SeaGL 2017 — @genehack 63
  64. 64. [alias] br = branch ci = commit -v co = checkout st = status Logs Are MAGIC — SeaGL 2017 — @genehack 64
  65. 65. aliases have many uses…Logs Are MAGIC — SeaGL 2017 — @genehack 65
  66. 66. Logs Are MAGIC — SeaGL 2017 — @genehack 66
  67. 67. back to keeping it clean…Logs Are MAGIC — SeaGL 2017 — @genehack 67
  68. 68. clean up remote branches Logs Are MAGIC — SeaGL 2017 — @genehack 68
  69. 69. git push origin :<branch> Logs Are MAGIC — SeaGL 2017 — @genehack 69
  70. 70. git push origin --delete <branch> Logs Are MAGIC — SeaGL 2017 — @genehack 70
  71. 71. nuke = push origin --delete Logs Are MAGIC — SeaGL 2017 — @genehack 71
  72. 72. clean up orphaned remote-tracking branchesLogs Are MAGIC — SeaGL 2017 — @genehack 72
  73. 73. git remote prune origin Logs Are MAGIC — SeaGL 2017 — @genehack 73
  74. 74. prune = remote prune origin Logs Are MAGIC — SeaGL 2017 — @genehack 74
  75. 75. find unmerged branchesLogs Are MAGIC — SeaGL 2017 — @genehack 75
  76. 76. git branch --no-merged master Logs Are MAGIC — SeaGL 2017 — @genehack 76
  77. 77. git branch --no-merged --remote master Logs Are MAGIC — SeaGL 2017 — @genehack 77
  78. 78. unmerged = branch --no-merged remote-unmerged = branch --no-merged --remote Logs Are MAGIC — SeaGL 2017 — @genehack 78
  79. 79. keep it cleanLogs Are MAGIC — SeaGL 2017 — @genehack 79
  80. 80. one final note on branchesLogs Are MAGIC — SeaGL 2017 — @genehack 80
  81. 81. branch namesLogs Are MAGIC — SeaGL 2017 — @genehack 81
  82. 82. a branch is a ticketLogs Are MAGIC — SeaGL 2017 — @genehack 82
  83. 83. the ticket id should be in the branch name Logs Are MAGIC — SeaGL 2017 — @genehack 83
  84. 84. along with something for the humansLogs Are MAGIC — SeaGL 2017 — @genehack 84
  85. 85. put the number at the end of the branch name Logs Are MAGIC — SeaGL 2017 — @genehack 85
  86. 86. ok: fix-login-864 Logs Are MAGIC — SeaGL 2017 — @genehack 86
  87. 87. meh: fix-864Logs Are MAGIC — SeaGL 2017 — @genehack 87
  88. 88. bad: 864-crapLogs Are MAGIC — SeaGL 2017 — @genehack 88
  89. 89. !!!: foobarLogs Are MAGIC — SeaGL 2017 — @genehack 89
  90. 90. maybe. just. don’t.Logs Are MAGIC — SeaGL 2017 — @genehack 90
  91. 91. include the branch name in the commit when merging Logs Are MAGIC — SeaGL 2017 — @genehack 91
  92. 92. the default message works nicely Logs Are MAGIC — SeaGL 2017 — @genehack 92
  93. 93. Merge branch <name> Logs Are MAGIC — SeaGL 2017 — @genehack 93
  94. 94. maximal historical informationLogs Are MAGIC — SeaGL 2017 — @genehack 94
  95. 95. to review Logs Are MAGIC — SeaGL 2017 — @genehack 95
  96. 96. don’t squash Logs Are MAGIC — SeaGL 2017 — @genehack 96
  97. 97. don’t fast forward Logs Are MAGIC — SeaGL 2017 — @genehack 97
  98. 98. don’t rebase before merge Logs Are MAGIC — SeaGL 2017 — @genehack 98
  99. 99. don’t destroy your history Logs Are MAGIC — SeaGL 2017 — @genehack 99
  100. 100. use branches Logs Are MAGIC — SeaGL 2017 — @genehack 100
  101. 101. use a release branch Logs Are MAGIC — SeaGL 2017 — @genehack 101
  102. 102. use no-ff to make merge commits Logs Are MAGIC — SeaGL 2017 — @genehack 102
  103. 103. keep your repo cleanLogs Are MAGIC — SeaGL 2017 — @genehack 103
  104. 104. let’s get more granular Logs Are MAGIC — SeaGL 2017 — @genehack 104
  105. 105. structuring individual commitsLogs Are MAGIC — SeaGL 2017 — @genehack 105
  106. 106. a commit equals one “change” Logs Are MAGIC — SeaGL 2017 — @genehack 106
  107. 107. important: at each commit the software must workLogs Are MAGIC — SeaGL 2017 — @genehack 107
  108. 108. git bisect Logs Are MAGIC — SeaGL 2017 — @genehack 108
  109. 109. smaller >> bigger Logs Are MAGIC — SeaGL 2017 — @genehack 109
  110. 110. whitespace & formatting Logs Are MAGIC — SeaGL 2017 — @genehack 110
  111. 111. always go in distinct commitsLogs Are MAGIC — SeaGL 2017 — @genehack 111
  112. 112. remember! Logs Are MAGIC — SeaGL 2017 — @genehack 112
  113. 113. revision is also a thing Logs Are MAGIC — SeaGL 2017 — @genehack 113
  114. 114. what you eventually push Logs Are MAGIC — SeaGL 2017 — @genehack 114
  115. 115. !=Logs Are MAGIC — SeaGL 2017 — @genehack 115
  116. 116. your commits while working Logs Are MAGIC — SeaGL 2017 — @genehack 116
  117. 117. savepoints Logs Are MAGIC — SeaGL 2017 — @genehack 117
  118. 118. every working micro step Logs Are MAGIC — SeaGL 2017 — @genehack 118
  119. 119. single “change” 10-15 commits Logs Are MAGIC — SeaGL 2017 — @genehack 119
  120. 120. git add --patch Logs Are MAGIC — SeaGL 2017 — @genehack 120
  121. 121. git add -p Logs Are MAGIC — SeaGL 2017 — @genehack 121
  122. 122. git commit --amend Logs Are MAGIC — SeaGL 2017 — @genehack 122
  123. 123. editor supportLogs Are MAGIC — SeaGL 2017 — @genehack 123
  124. 124. magit fugitive github.atom.io Logs Are MAGIC — SeaGL 2017 — @genehack 124
  125. 125. magit Logs Are MAGIC — SeaGL 2017 — @genehack 125
  126. 126. don’t push first drafts Logs Are MAGIC — SeaGL 2017 — @genehack 126
  127. 127. tell a story Logs Are MAGIC — SeaGL 2017 — @genehack 127
  128. 128. interactive rebase git rebase -i Logs Are MAGIC — SeaGL 2017 — @genehack 128
  129. 129. sometimes may be useful to preserve dead ends Logs Are MAGIC — SeaGL 2017 — @genehack 129
  130. 130. ...as a warning for others Logs Are MAGIC — SeaGL 2017 — @genehack 130
  131. 131. commit messagesLogs Are MAGIC — SeaGL 2017 — @genehack 131
  132. 132. ticket numbers in the subject Logs Are MAGIC — SeaGL 2017 — @genehack 132
  133. 133. (at the end) Logs Are MAGIC — SeaGL 2017 — @genehack 133
  134. 134. keep the subject shortLogs Are MAGIC — SeaGL 2017 — @genehack 134
  135. 135. commit message bodiesLogs Are MAGIC — SeaGL 2017 — @genehack 135
  136. 136. Logs Are MAGIC — SeaGL 2017 — @genehack 136
  137. 137. you can customize the template for the commit message Logs Are MAGIC — SeaGL 2017 — @genehack 137
  138. 138. git config --local commit.template ./.template # edit .template to add whatever you want... Logs Are MAGIC — SeaGL 2017 — @genehack 138
  139. 139. commit message examples Logs Are MAGIC — SeaGL 2017 — @genehack 139
  140. 140. good: make login form use POST instead of GET [#864] Logs Are MAGIC — SeaGL 2017 — @genehack 140
  141. 141. meh:fixed form [#864] Logs Are MAGIC — SeaGL 2017 — @genehack 141
  142. 142. bad:846 fix Logs Are MAGIC — SeaGL 2017 — @genehack 142
  143. 143. !!!:foo Logs Are MAGIC — SeaGL 2017 — @genehack 143
  144. 144. ( °□° Logs Are MAGIC — SeaGL 2017 — @genehack 144
  145. 145. this is why daddy drinks Logs Are MAGIC — SeaGL 2017 — @genehack 145
  146. 146. to review Logs Are MAGIC — SeaGL 2017 — @genehack 146
  147. 147. 1 commit → 1 change Logs Are MAGIC — SeaGL 2017 — @genehack 147
  148. 148. commit messages matter! Logs Are MAGIC — SeaGL 2017 — @genehack 148
  149. 149. when in doubt make it smaller Logs Are MAGIC — SeaGL 2017 — @genehack 149
  150. 150. (make the commit smaller NOT the commit message) Logs Are MAGIC — SeaGL 2017 — @genehack 150
  151. 151. segregate formatting changes Logs Are MAGIC — SeaGL 2017 — @genehack 151
  152. 152. use checkpoint commits as savepoints Logs Are MAGIC — SeaGL 2017 — @genehack 152
  153. 153. don’t push first drafts Logs Are MAGIC — SeaGL 2017 — @genehack 153
  154. 154. revise to tell a story Logs Are MAGIC — SeaGL 2017 — @genehack 154
  155. 155. or at least make yourself look smartLogs Are MAGIC — SeaGL 2017 — @genehack 155
  156. 156. using history betterLogs Are MAGIC — SeaGL 2017 — @genehack 156
  157. 157. jfriLogs Are MAGIC — SeaGL 2017 — @genehack 157
  158. 158. just friggin’ read itLogs Are MAGIC — SeaGL 2017 — @genehack 158
  159. 159. ~/.gitconfig (again) Logs Are MAGIC — SeaGL 2017 — @genehack 159
  160. 160. color supportLogs Are MAGIC — SeaGL 2017 — @genehack 160
  161. 161. [color] branch = auto diff = auto grep = auto interactive = auto showbranch = auto status = auto ui = auto Logs Are MAGIC — SeaGL 2017 — @genehack 161
  162. 162. [color "status"] added = green bold changed = red bold untracked = cyan bold Logs Are MAGIC — SeaGL 2017 — @genehack 162
  163. 163. git diff Logs Are MAGIC — SeaGL 2017 — @genehack 163
  164. 164. git diff Logs Are MAGIC — SeaGL 2017 — @genehack 164
  165. 165. git diff --word-diff Logs Are MAGIC — SeaGL 2017 — @genehack 165
  166. 166. blame Logs Are MAGIC — SeaGL 2017 — @genehack 166
  167. 167. git blame Logs Are MAGIC — SeaGL 2017 — @genehack 167
  168. 168. git blame -w -M Logs Are MAGIC — SeaGL 2017 — @genehack 168
  169. 169. [alias] praise = blame Logs Are MAGIC — SeaGL 2017 — @genehack 169
  170. 170. i will buy this tee shirt hashtag justsayin’ Logs Are MAGIC — SeaGL 2017 — @genehack 170
  171. 171. editor integrationLogs Are MAGIC — SeaGL 2017 — @genehack 171
  172. 172. M-x git-blame-for-line Logs Are MAGIC — SeaGL 2017 — @genehack 172
  173. 173. git blame -L <line>,<line> <file> git log -L <line>,<line>:<file> Logs Are MAGIC — SeaGL 2017 — @genehack 173
  174. 174. git blame -L 1,1 index.html Logs Are MAGIC — SeaGL 2017 — @genehack 174
  175. 175. git blame -L 10,50 index.html Logs Are MAGIC — SeaGL 2017 — @genehack 175
  176. 176. git blame -L 20,+10 index.html Logs Are MAGIC — SeaGL 2017 — @genehack 176
  177. 177. git log -L 1,1:index.html Logs Are MAGIC — SeaGL 2017 — @genehack 177
  178. 178. git log -L 10,50:index.html Logs Are MAGIC — SeaGL 2017 — @genehack 178
  179. 179. git log -L 20,+10:index.html Logs Are MAGIC — SeaGL 2017 — @genehack 179
  180. 180. git log -S <string> Logs Are MAGIC — SeaGL 2017 — @genehack 180
  181. 181. git lg Logs Are MAGIC — SeaGL 2017 — @genehack 181
  182. 182. log --graph --abbrev-commit --date=relative --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' Logs Are MAGIC — SeaGL 2017 — @genehack 182
  183. 183. Logs Are MAGIC — SeaGL 2017 — @genehack 183
  184. 184. --graph Logs Are MAGIC — SeaGL 2017 — @genehack 184
  185. 185. Logs Are MAGIC — SeaGL 2017 — @genehack 185
  186. 186. --abbrev-commit Logs Are MAGIC — SeaGL 2017 — @genehack 186
  187. 187. Logs Are MAGIC — SeaGL 2017 — @genehack 187
  188. 188. --date=relative Logs Are MAGIC — SeaGL 2017 — @genehack 188
  189. 189. Logs Are MAGIC — SeaGL 2017 — @genehack 189
  190. 190. --pretty=format: '%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' Logs Are MAGIC — SeaGL 2017 — @genehack 190
  191. 191. Logs Are MAGIC — SeaGL 2017 — @genehack 191
  192. 192. takeaways! Logs Are MAGIC — SeaGL 2017 — @genehack 192
  193. 193. history is important Logs Are MAGIC — SeaGL 2017 — @genehack 193
  194. 194. it’s probably worth more of your time Logs Are MAGIC — SeaGL 2017 — @genehack 194
  195. 195. both creating it and using it Logs Are MAGIC — SeaGL 2017 — @genehack 195
  196. 196. don’t just stop when the software worksLogs Are MAGIC — SeaGL 2017 — @genehack 196
  197. 197. software development is hardLogs Are MAGIC — SeaGL 2017 — @genehack 197
  198. 198. be kind to othersLogs Are MAGIC — SeaGL 2017 — @genehack 198
  199. 199. be kind to your future selfLogs Are MAGIC — SeaGL 2017 — @genehack 199
  200. 200. thank you!Logs Are MAGIC — SeaGL 2017 — @genehack 200
  201. 201. Logs Are MAGIC — SeaGL 2017 — @genehack 201
  202. 202. questions? Logs Are MAGIC — SeaGL 2017 — @genehack 202

×