Fossil SCM

fossil-scm / www / rebaseharm.md
Source Blame History 522 lines
4f79941… drh 1 # Rebase Considered Harmful
4f79941… drh 2
5a7cda5… wyoung 3 Fossil deliberately omits a "rebase" command because the original
fd1282e… drh 4 designer of Fossil (and [original author][vhist] of this article) considers rebase to be
4f79941… drh 5 an anti-pattern to be avoided. This article attempts to
4f79941… drh 6 explain that point of view.
569cc74… drh 7
80f9825… drh 8 [vhist]: /finfo?name=www/rebaseharm.md&ubg
cd689b3… wyoung 9
237bde9… drh 10 ## 1.0 Rebasing is dangerous
237bde9… drh 11
cd689b3… wyoung 12 Most people, even strident advocates of rebase, agree that rebase can
cd689b3… wyoung 13 cause problems when misused. The Git rebase documentation talks about the
5a7cda5… wyoung 14 [golden rule of rebasing][golden]: never rebase on a public
fd1282e… drh 15 branch. Horror stories of misused rebase abound, and the rebase
9b32c18… drh 16 documentation devotes considerable space toward explaining how to
9b32c18… drh 17 recover from rebase errors and/or misuse.
9b32c18… drh 18
93cee1f… wyoung 19 ## <a id="cap-loss"></a>2.0 Rebase provides no new capabilities
cd689b3… wyoung 20
4f79941… drh 21 Sometimes sharp and dangerous tools are justified,
4f79941… drh 22 because they accomplish things that cannot be
cd689b3… wyoung 23 done otherwise, or at least cannot be done easily.
cd689b3… wyoung 24 Rebase does not fall into that category,
cd689b3… wyoung 25 because it provides no new capabilities.
4f79941… drh 26
93cee1f… wyoung 27 ### <a id="orphaning"></a>2.1 A rebase is just a merge with historical references omitted
4f79941… drh 28
4f79941… drh 29 A rebase is really nothing more than a merge (or a series of merges)
4f79941… drh 30 that deliberately forgets one of the parents of each merge step.
4f79941… drh 31 To help illustrate this fact,
fd1282e… drh 32 consider the first rebase example from the
4f79941… drh 33 [Git documentation][gitrebase]. The merge looks like this:
4f79941… drh 34
9607f5b… wyoung 35 ~~~ pikchr toggle center
38d6a8f… drh 36 scale = 0.8
38d6a8f… drh 37 circle "C0" fit
38d6a8f… drh 38 arrow right 50%
38d6a8f… drh 39 circle same "C1"
38d6a8f… drh 40 arrow same
38d6a8f… drh 41 circle same "C2"
38d6a8f… drh 42 arrow same
38d6a8f… drh 43 circle same "C3"
38d6a8f… drh 44 arrow same
38d6a8f… drh 45 circle same "C5"
38d6a8f… drh 46 circle same "C4" at 1cm above C3
38d6a8f… drh 47 arrow from C2 to C4 chop
38d6a8f… drh 48 arrow from C4 to C5 chop
38d6a8f… drh 49 ~~~
4f79941… drh 50
4f79941… drh 51 And the rebase looks like this:
4f79941… drh 52
9607f5b… wyoung 53 ~~~ pikchr toggle center
38d6a8f… drh 54 scale = 0.8
38d6a8f… drh 55 circle "C0" fit
38d6a8f… drh 56 arrow right 50%
38d6a8f… drh 57 circle same "C1"
38d6a8f… drh 58 arrow same
38d6a8f… drh 59 circle same "C2"
38d6a8f… drh 60 arrow same
38d6a8f… drh 61 circle same "C3"
38d6a8f… drh 62 arrow same
38d6a8f… drh 63 circle same "C4'"
38d6a8f… drh 64 circle same "C4" at 1cm above C3
38d6a8f… drh 65 arrow from C2 to C4 chop
38d6a8f… drh 66 ~~~
4f79941… drh 67
4f79941… drh 68 As the [Git documentation][gitrebase] points out, check-ins C4\' and C5
4f79941… drh 69 are identical. The only difference between C4\' and C5 is that C5
4f79941… drh 70 records the fact that C4 is its merge parent but C4\' does not.
4f79941… drh 71
4f79941… drh 72 Thus, a rebase is just a merge that forgets where it came from.
4f79941… drh 73
4f79941… drh 74 The Git documentation acknowledges this fact (in so many words) and
cd689b3… wyoung 75 justifies it by saying "rebasing makes for a cleaner history." I read
fd1282e… drh 76 that sentence as a tacit admission that the Git history display
fd1282e… drh 77 capabilities are weak and need active assistance from the user to
4f79941… drh 78 keep things manageable.
4f79941… drh 79 Surely a better approach is to record
4f79941… drh 80 the complete ancestry of every check-in but then fix the tool to show
4f79941… drh 81 a "clean" history in those instances where a simplified display is
9b32c18… drh 82 desirable and edifying, but retain the option to show the real,
4f79941… drh 83 complete, messy history for cases where detail and accuracy are more
4f79941… drh 84 important.
4f79941… drh 85
4f79941… drh 86 So, another way of thinking about rebase is that it is a kind of
049c42d… andybradford 87 merge that intentionally forgets some details in order to
4f79941… drh 88 not overwhelm the weak history display mechanisms available in Git.
5a7cda5… wyoung 89 Wouldn't it be better, less error-prone, and easier on users
fd1282e… drh 90 to enhance the history display mechanisms in Git so that rebasing
9b068a3… drh 91 for a clean, linear history became unnecessary?
237bde9… drh 92
93cee1f… wyoung 93 ### <a id="clean-diffs"></a>2.2 Rebase does not actually provide better feature-branch diffs
4f79941… drh 94
4f79941… drh 95 Another argument, often cited, is that rebasing a feature branch
4f79941… drh 96 allows one to see just the changes in the feature branch without
fd1282e… drh 97 the concurrent changes in the main line of development.
4f79941… drh 98 Consider a hypothetical case:
4f79941… drh 99
9607f5b… wyoung 100 ~~~ pikchr toggle center
38d6a8f… drh 101 scale = 0.8
38d6a8f… drh 102 circle "C0" fit fill white
38d6a8f… drh 103 arrow right 50%
38d6a8f… drh 104 circle same "C1"
38d6a8f… drh 105 arrow same
38d6a8f… drh 106 circle same "C2"
38d6a8f… drh 107 arrow same
38d6a8f… drh 108 circle same "C4"
38d6a8f… drh 109 arrow same
38d6a8f… drh 110 circle same "C6"
38d6a8f… drh 111 circle same "C3" at last arrow.width + C0.rad*2 heading 30 from C2
38d6a8f… drh 112 arrow right 50%
38d6a8f… drh 113 circle same "C5"
38d6a8f… drh 114 arrow from C2 to C3 chop
38d6a8f… drh 115 box ht C3.y-C2.y wid C6.e.x-C0.w.x+1.5*C1.rad at C2 behind C0 fill 0xc6e2ff color 0xaac5df
38d6a8f… drh 116 box ht previous.ht wid previous.wid*0.55 with .se at previous.ne \
38d6a8f… drh 117 behind C0 fill 0x9accfc color 0xaac5df
38d6a8f… drh 118 text "feature" with .s at previous.n
38d6a8f… drh 119 text "main" with .n at first box.s
38d6a8f… drh 120 ~~~
4f79941… drh 121
4f79941… drh 122 In the above, a feature branch consisting of check-ins C3 and C5 is
4f79941… drh 123 run concurrently with the main line in check-ins C4 and C6. Advocates
4f79941… drh 124 for rebase say that you should rebase the feature branch to the tip
5a7cda5… wyoung 125 of main in order to remove main-line development differences from
5a7cda5… wyoung 126 the feature branch's history:
c71fe99… wyoung 127
9607f5b… wyoung 128 ~~~ pikchr toggle center
a61ac66… wyoung 129 # Duplicated below in section 5.0
38d6a8f… drh 130 scale = 0.8
38d6a8f… drh 131 circle "C0" fit fill white
38d6a8f… drh 132 arrow right 50%
38d6a8f… drh 133 circle same "C1"
38d6a8f… drh 134 arrow same
38d6a8f… drh 135 circle same "C2"
38d6a8f… drh 136 arrow same
38d6a8f… drh 137 circle same "C4"
38d6a8f… drh 138 arrow same
38d6a8f… drh 139 circle same "C6"
38d6a8f… drh 140 circle same "C3" at last arrow.width + C0.rad*2 heading 30 from C2
38d6a8f… drh 141 arrow right 50%
38d6a8f… drh 142 circle same "C5"
38d6a8f… drh 143 arrow from C2 to C3 chop
38d6a8f… drh 144 C3P: circle same "C3'" at first arrow.width + C0.rad*2 heading 30 from C6
38d6a8f… drh 145 arrow right 50% from C3P.e
38d6a8f… drh 146 C5P: circle same "C5'"
38d6a8f… drh 147 arrow from C6 to C3P chop
38d6a8f… drh 148
38d6a8f… drh 149 box ht C3.y-C2.y wid C5P.e.x-C0.w.x+1.5*C1.rad with .w at 0.5*(first arrow.wid) west of C0.w \
38d6a8f… drh 150 behind C0 fill 0xc6e2ff color 0xaac5df
38d6a8f… drh 151 box ht previous.ht wid previous.e.x - C2.w.x with .se at previous.ne \
38d6a8f… drh 152 behind C0 fill 0x9accfc color 0xaac5df
38d6a8f… drh 153 ~~~
38d6a8f… drh 154
c71fe99… wyoung 155
c71fe99… wyoung 156 You could choose to collapse C3\' and C5\' into a single check-in
6a903b3… drh 157 as part of this rebase, but that's a side issue we'll deal with
c71fe99… wyoung 158 [separately](#collapsing).
c71fe99… wyoung 159
be9df83… wyoung 160 Because Fossil purposefully lacks rebase, the closest you can get to this same check-in
5a7cda5… wyoung 161 history is the following merge:
5a7cda5… wyoung 162
9607f5b… wyoung 163 ~~~ pikchr toggle center
38d6a8f… drh 164 scale = 0.8
38d6a8f… drh 165 circle "C0" fit fill white
38d6a8f… drh 166 arrow right 50%
38d6a8f… drh 167 circle same "C1"
38d6a8f… drh 168 arrow same
38d6a8f… drh 169 circle same "C2"
38d6a8f… drh 170 arrow same
38d6a8f… drh 171 circle same "C4"
38d6a8f… drh 172 arrow same
38d6a8f… drh 173 circle same "C6"
38d6a8f… drh 174 circle same "C3" at last arrow.width + C0.rad*2 heading 30 from C2
38d6a8f… drh 175 arrow right 50%
38d6a8f… drh 176 circle same "C5"
38d6a8f… drh 177 arrow same
38d6a8f… drh 178 circle same "C7"
38d6a8f… drh 179 arrow from C2 to C3 chop
38d6a8f… drh 180 arrow from C6 to C7 chop
38d6a8f… drh 181
38d6a8f… drh 182 box ht C3.y-C2.y wid C7.e.x-C0.w.x+1.5*C1.rad with .w at 0.5*(first arrow.wid) west of C0.w \
38d6a8f… drh 183 behind C0 fill 0xc6e2ff color 0xaac5df
38d6a8f… drh 184 box ht previous.ht wid previous.e.x - C2.w.x with .se at previous.ne \
38d6a8f… drh 185 behind C0 fill 0x9accfc color 0xaac5df
38d6a8f… drh 186 ~~~
38d6a8f… drh 187
4f79941… drh 188
4f79941… drh 189 Check-ins C5\' and C7 check-ins hold identical code. The only
fd1282e… drh 190 difference is in their history.
4f79941… drh 191
4f79941… drh 192 The argument from rebase advocates
4f79941… drh 193 is that with merge it is difficult to see only the changes associated
4f79941… drh 194 with the feature branch without the commingled mainline changes.
5a7cda5… wyoung 195 In other words, diff(C2,C7) shows changes from both the feature
708696d… wyoung 196 branch and from the mainline, whereas in the rebase case
5a7cda5… wyoung 197 diff(C6,C5\') shows only the feature branch changes.
4f79941… drh 198
4f79941… drh 199 But that argument is comparing apples to oranges, since the two diffs
4f79941… drh 200 do not have the same baseline. The correct way to see only the feature
4f79941… drh 201 branch changes in the merge case is not diff(C2,C7) but rather diff(C6,C7).
4f79941… drh 202
9607f5b… wyoung 203 <div align=center>
9607f5b… wyoung 204
9607f5b… wyoung 205 | Rebase | Merge | What You See |
9607f5b… wyoung 206 |---------------|-------------|----------------------------------------|
9607f5b… wyoung 207 | diff(C2,C5\') | diff(C2,C7) | Commingled branch and mainline changes |
9607f5b… wyoung 208 | diff(C6,C5\') | diff(C6,C7) | Branch changes only |
9607f5b… wyoung 209
9607f5b… wyoung 210 </div>
708696d… wyoung 211
708696d… wyoung 212 Remember: C7 and C5\' are bit-for-bit identical, so the output of the
708696d… wyoung 213 diff is not determined by whether you select C7 or C5\' as the target
4f79941… drh 214 of the diff, but rather by your choice of the diff source, C2 or C6.
4f79941… drh 215
708696d… wyoung 216 So, to help with the problem of viewing changes associated with a feature
fd1282e… drh 217 branch, perhaps what is needed is not rebase but rather better tools to
4f79941… drh 218 help users identify an appropriate baseline for their diffs.
4f79941… drh 219
93cee1f… wyoung 220 ## <a id="siloing"></a>3.0 Rebase encourages siloed development
4f79941… drh 221
5a7cda5… wyoung 222 The [golden rule of rebasing][golden] is that you should never do it
708696d… wyoung 223 on public branches, so if you are using rebase as intended, that means
4f79941… drh 224 you are keeping private branches. Or, to put it another way, you are
4f79941… drh 225 doing siloed development. You are not sharing your intermediate work
4f79941… drh 226 with collaborators. This is not good for product quality.
4f79941… drh 227
4f79941… drh 228 [Nagappan, et. al][nagappan] studied bugs in Windows Vista and found
a186d8b… drh 229 that the best predictor of bugs is the distance on the org-chart between
5a7cda5… wyoung 230 the stake-holders. The bug rate is inversely related to the
5a7cda5… wyoung 231 amount of communication among the engineers.
5a7cda5… wyoung 232 Similar findings arise in other disciplines. Keeping
9b32c18… drh 233 private branches does not prove that developers are communicating
a186d8b… drh 234 insufficiently, but it is a key symptom of that problem.
18e58e2… drh 235
cd689b3… wyoung 236 [Weinberg][weinberg] argues programming should be "egoless." That
18e58e2… drh 237 is to say, programmers should avoid linking their code with their sense of
aaacce2… drh 238 self, as that makes it more difficult for them to find and respond
4f79941… drh 239 to bugs, and hence makes them less productive. Many developers are
4f79941… drh 240 drawn to private branches out of sense of ego. "I want to get the
cd689b3… wyoung 241 code right before I publish it." I sympathize with this sentiment,
4f79941… drh 242 and am frequently guilty of it myself. It is humbling to display
5a7cda5… wyoung 243 your stupid mistake to the whole world on an Internet that
4f79941… drh 244 never forgets. And yet, humble programmers generate better code.
4f79941… drh 245
924bf44… wyoung 246 What is the fastest path to solid code? Is it to continue staring at
924bf44… wyoung 247 your private branch to seek out every last bug, or is it to publish it
924bf44… wyoung 248 as-is, whereupon the many eyeballs will immediately see that last stupid
924bf44… wyoung 249 error in the code? Testing and development are often done by separate
924bf44… wyoung 250 groups within a larger software development organization, because
924bf44… wyoung 251 developers get too close to their own code to see every problem in it.
924bf44… wyoung 252
924bf44… wyoung 253 Given that, is it better for those many eyeballs to find your problems
6a903b3… drh 254 while they're still isolated on a feature branch, or should that vetting
924bf44… wyoung 255 wait until you finally push a collapsed version of a private working
924bf44… wyoung 256 branch to the parent repo? Will the many eyeballs even see those errors
9b068a3… drh 257 when they’re intermingled with code implementing some compelling new feature?
9b068a3… drh 258
93cee1f… wyoung 259 ## <a id="timestamps"></a>4.0 Rebase causes timestamp confusion
4f79941… drh 260
4f79941… drh 261 Consider the earlier example of rebasing a feature branch:
4f79941… drh 262
9607f5b… wyoung 263 ~~~ pikchr toggle center
a61ac66… wyoung 264 # Copy of second diagram in section 2.2 above
a61ac66… wyoung 265 scale = 0.8
a61ac66… wyoung 266 circle "C0" fit fill white
a61ac66… wyoung 267 arrow right 50%
a61ac66… wyoung 268 circle same "C1"
a61ac66… wyoung 269 arrow same
a61ac66… wyoung 270 circle same "C2"
a61ac66… wyoung 271 arrow same
a61ac66… wyoung 272 circle same "C4"
a61ac66… wyoung 273 arrow same
a61ac66… wyoung 274 circle same "C6"
a61ac66… wyoung 275 circle same "C3" at last arrow.width + C0.rad*2 heading 30 from C2
a61ac66… wyoung 276 arrow right 50%
a61ac66… wyoung 277 circle same "C5"
a61ac66… wyoung 278 arrow from C2 to C3 chop
a61ac66… wyoung 279 C3P: circle same "C3'" at first arrow.width + C0.rad*2 heading 30 from C6
a61ac66… wyoung 280 arrow right 50% from C3P.e
a61ac66… wyoung 281 C5P: circle same "C5'"
a61ac66… wyoung 282 arrow from C6 to C3P chop
a61ac66… wyoung 283
a61ac66… wyoung 284 box ht C3.y-C2.y wid C5P.e.x-C0.w.x+1.5*C1.rad with .w at 0.5*(first arrow.wid) west of C0.w \
a61ac66… wyoung 285 behind C0 fill 0xc6e2ff color 0xaac5df
a61ac66… wyoung 286 box ht previous.ht wid previous.e.x - C2.w.x with .se at previous.ne \
a61ac66… wyoung 287 behind C0 fill 0x9accfc color 0xaac5df
a61ac66… wyoung 288 ~~~
4f79941… drh 289
4f79941… drh 290 What timestamps go on the C3\' and C5\' check-ins? If you choose
4f79941… drh 291 the same timestamps as the original C3 and C5, then you have the
4f79941… drh 292 odd situation C3' is older than its parent C6. We call that a
4f79941… drh 293 "timewarp" in Fossil. Timewarps can also happen due to misconfigured
5a7cda5… wyoung 294 system clocks, so they are not unique to rebase, but they are very
5a7cda5… wyoung 295 confusing and so best avoided. The other option is to provide new
5a7cda5… wyoung 296 unique timestamps for C3' and C5' but then you lose the information
4f79941… drh 297 about when those check-ins were originally created, which can make
5a7cda5… wyoung 298 historical analysis of changes more difficult. It might also
5a7cda5… wyoung 299 complicate the legal defense of prior art claims.
4f79941… drh 300
93cee1f… wyoung 301 ## <a id="lying"></a>5.0 Rebase misrepresents the project history
4f79941… drh 302
4f79941… drh 303 By discarding parentage information, rebase attempts to deceive the
4f79941… drh 304 reader about how the code actually came together.
4f79941… drh 305
19d0a94… drh 306 Git’s rebase feature is more than just an
1a4b8e5… wyoung 307 alternative to merging: it also provides mechanisms for changing the
1a4b8e5… wyoung 308 project history in order to make editorial changes. Fossil shows that
1a4b8e5… wyoung 309 you can get similar effects without modifying historical records,
1a4b8e5… wyoung 310 allowing users to:
9b068a3… drh 311
9b068a3… drh 312 1. Edit check-in comments to fix typos or enhance clarity
9b068a3… drh 313 2. Attach supplemental notes to check-ins or whole branches
1a4b8e5… wyoung 314 3. Hide ill-conceived or now-unused branches from routine display
1a4b8e5… wyoung 315 4. Fix faulty check-in date/times resulting from misconfigured
9b068a3… drh 316 system clocks
1a4b8e5… wyoung 317 5. Cross-reference check-ins with each other, or with
1a4b8e5… wyoung 318 wiki, tickets, forum posts, and/or embedded documentation
068e26a… wyoung 319
068e26a… wyoung 320 …and so forth.
6a903b3… drh 321
1a4b8e5… wyoung 322 Fossil allows all of this not by removing or modifying existing
6a903b3… drh 323 repository entries, but rather by adding new supplemental records.
1a4b8e5… wyoung 324 Fossil keeps the original incorrect or unclear inputs and makes them
1a4b8e5… wyoung 325 readily accessible, preserving the original historical record. Fossil
1a4b8e5… wyoung 326 doesn’t make the user tell counter-factual “stories,” it only allows the
1a4b8e5… wyoung 327 user to provide annotations to provide a more readable edited
1a4b8e5… wyoung 328 presentation for routine display purposes.
1a4b8e5… wyoung 329
1a4b8e5… wyoung 330 Git needs rebase because it lacks these annotation facilities. Rather
1a4b8e5… wyoung 331 than consider rebase a desirable feature missing in Fossil, ask instead
1a4b8e5… wyoung 332 why Git lacks support for making editorial changes to check-ins without
e755561… danield 333 modifying history? Wouldn't it be better to fix the version control
1a4b8e5… wyoung 334 tool rather than requiring users to fabricate a fictitious project
1a4b8e5… wyoung 335 history?
1a4b8e5… wyoung 336
93cee1f… wyoung 337 ## <a id="collapsing"></a>6.0 Collapsing check-ins throws away valuable information
c71fe99… wyoung 338
c71fe99… wyoung 339 One of the oft-cited advantages of rebasing in Git is that it lets you
c71fe99… wyoung 340 collapse multiple check-ins down to a single check-in to make the
c71fe99… wyoung 341 development history “clean.” The intent is that development appear as
c71fe99… wyoung 342 though every feature were created in a single step: no multi-step
c71fe99… wyoung 343 evolution, no back-tracking, no false starts, no mistakes. This ignores
c71fe99… wyoung 344 actual developer psychology: ideas rarely spring forth from fingers to
c71fe99… wyoung 345 files in faultless finished form. A wish for collapsed, finalized
c71fe99… wyoung 346 check-ins is a wish for a counterfactual situation.
c71fe99… wyoung 347
c71fe99… wyoung 348 The common counterargument is that collapsed check-ins represent a
6a903b3… drh 349 better world, the ideal we're striving for. What that argument overlooks
c71fe99… wyoung 350 is that we must throw away valuable information to get there.
c71fe99… wyoung 351
93cee1f… wyoung 352 ### <a id="empathy"></a>6.1 Individual check-ins support mutual understanding
c71fe99… wyoung 353
c71fe99… wyoung 354 Ideally, future developers of our software can understand every feature
c71fe99… wyoung 355 in it using only context available in the version of the code they start
c71fe99… wyoung 356 work with. Prior to widespread version control, developers had no choice
c71fe99… wyoung 357 but to work that way. Pre-existing codebases could only be understood
c71fe99… wyoung 358 as-is or not at all. Developers in that world had an incentive to
c71fe99… wyoung 359 develop software that was easy to understand retrospectively, even if
c71fe99… wyoung 360 they were selfish people, because they knew they might end up being
c71fe99… wyoung 361 those future developers!
c71fe99… wyoung 362
c71fe99… wyoung 363 Yet, sometimes we come upon a piece of code that we simply cannot
5a7cda5… wyoung 364 understand. If you have never asked yourself, "What was this code's
6a903b3… drh 365 developer thinking?" you haven't been developing software for very long.
c71fe99… wyoung 366
c71fe99… wyoung 367 When a developer can go back to the individual check-ins leading up to
c71fe99… wyoung 368 the current code, they can work out the answers to such questions using
068e26a… wyoung 369 only the level of personal brilliance necessary to be a good developer. To
c71fe99… wyoung 370 understand such code using only the finished form, you are asking future
c71fe99… wyoung 371 developers to make intuitive leaps that the original developer was
c71fe99… wyoung 372 unable to make. In other words, you are asking your future maintenance
6a903b3… drh 373 developers to be smarter than the original developers! That's a
6a903b3… drh 374 beautiful wish, but there's a sharp limit to how far you can carry it.
c71fe99… wyoung 375 Eventually you hit the limits of human brilliance.
c71fe99… wyoung 376
c71fe99… wyoung 377 When the operation of some bit of code is not obvious, both Fossil and
c64f28d… drh 378 Git let you run a [`blame`](/help/blame) on the code file to get
c71fe99… wyoung 379 information about each line of code, and from that which check-in last
c71fe99… wyoung 380 touched a given line of code. If you squash the check-ins on a branch
c71fe99… wyoung 381 down to a single check-in, you throw away the information leading up to
c71fe99… wyoung 382 that finished form. Fossil not only preserves the check-ins surrounding
6a903b3… drh 383 the one that included the line of code you're trying to understand, its
c71fe99… wyoung 384 [superior data model][sdm] lets you see the surrounding check-ins in
c71fe99… wyoung 385 both directions; not only what lead up to it, but what came next. Git
6a903b3… drh 386 can't do that short of crawling the block-chain backwards from the tip
c71fe99… wyoung 387 of the branch to the check-in you’re looking at, an expensive operation.
c71fe99… wyoung 388
c71fe99… wyoung 389 We believe it is easier to understand a line of code from the 10-line
c71fe99… wyoung 390 check-in it was a part of — and then to understand the surrounding
c71fe99… wyoung 391 check-ins as necessary — than it is to understand a 500-line check-in
6a903b3… drh 392 that collapses a whole branch's worth of changes down to a single
c71fe99… wyoung 393 finished feature.
c71fe99… wyoung 394
c71fe99… wyoung 395 [sdm]: ./fossil-v-git.wiki#durable
c71fe99… wyoung 396
93cee1f… wyoung 397 ### <a id="bisecting"></a>6.2 Bisecting works better on small check-ins
c71fe99… wyoung 398
c71fe99… wyoung 399 Git lets a developer write a feature in ten check-ins but collapse it
c71fe99… wyoung 400 down to an eleventh check-in and then deliberately push only that final
c71fe99… wyoung 401 collapsed check-in to the parent repo. Someone else may then do a bisect
c71fe99… wyoung 402 that blames the merged check-in as the source of the problem they’re
c71fe99… wyoung 403 chasing down; they then have to manually work out which of the 10 steps
c71fe99… wyoung 404 the original developer took to create it to find the source of the
c71fe99… wyoung 405 actual problem.
c71fe99… wyoung 406
b16db9d… wyoung 407 An equivalent push in Fossil will send all 11 check-ins to the parent
b16db9d… wyoung 408 repository so that a later investigator doing the same sort of bisect
b16db9d… wyoung 409 sees the complete check-in history. That bisect will point the
b16db9d… wyoung 410 investigator at the single original check-in that caused the problem.
c71fe99… wyoung 411
93cee1f… wyoung 412 ### <a id="comments"></a>6.3 Multiple check-ins require multiple check-in comments
c71fe99… wyoung 413
c71fe99… wyoung 414 The more comments you have from a given developer on a given body of
5a7cda5… wyoung 415 code, the more concise documentation you have of that developer's
c71fe99… wyoung 416 thought process. To resume the bisecting example, a developer trying to
c71fe99… wyoung 417 work out what the original developer was thinking with a given change
c71fe99… wyoung 418 will have more success given a check-in comment that explains what the
6a903b3… drh 419 one check-in out of ten blamed by the "bisect" command was trying to
6a903b3… drh 420 accomplish than if they must work that out from the eleventh check-in's
6a903b3… drh 421 comment, which only explains the "clean" version of the collapsed
c71fe99… wyoung 422 feature.
c71fe99… wyoung 423
93cee1f… wyoung 424 ### <a id="cherrypicking"></a>6.4 Cherry-picks work better with small check-ins
c71fe99… wyoung 425
c71fe99… wyoung 426 While working on a new feature in one branch, you may come across a bug
c71fe99… wyoung 427 in the pre-existing code that you need to fix in order for work on that
c71fe99… wyoung 428 feature to proceed. You could choose to switch briefly back to the
c71fe99… wyoung 429 parent branch, develop the fix there, check it in, then merge the parent
6a903b3… drh 430 back up to the feature branch in order to continue work, but that's
6a903b3… drh 431 distracting. If the fix isn't for a critical bug, fixing it on the
6a903b3… drh 432 parent branch can wait, so it's better to maintain your mental working
c71fe99… wyoung 433 state by fixing the problem in place on the feature branch, then check
c71fe99… wyoung 434 the fix in on the feature branch, resume work on the feature, and later
c71fe99… wyoung 435 merge that fix down into the parent branch along with the feature.
c71fe99… wyoung 436
c71fe99… wyoung 437 But now what happens if another branch *also* needs that fix? Let us say
c71fe99… wyoung 438 our code repository has a branch for the current stable release, a
c71fe99… wyoung 439 development branch for the next major version, and feature branches off
c71fe99… wyoung 440 of the development branch. If we rebase each feature branch down into
c71fe99… wyoung 441 the development branch as a single check-in, pushing only the rebase
6a903b3… drh 442 check-in up to the parent repo, only that fix's developer has the
c71fe99… wyoung 443 information locally to perform the cherry-pick of the fix onto the
c71fe99… wyoung 444 stable branch.
c71fe99… wyoung 445
c71fe99… wyoung 446 Developers working on new features often do not care about old stable
c71fe99… wyoung 447 versions, yet that stable version may have an end user community that
c71fe99… wyoung 448 depends on that version, who either cannot wait for the next stable
c71fe99… wyoung 449 version or who wish to put off upgrading to it for some time. Such users
c71fe99… wyoung 450 want backported bug fixes, yet the developers creating those fixes have
c71fe99… wyoung 451 poor incentives to provide those backports. Thus the existence of
c71fe99… wyoung 452 maintenance and support organizations, who end up doing such work.
c71fe99… wyoung 453 (There is [a famous company][rh] that built a multi-billion dollar
c71fe99… wyoung 454 enterprise on such work.)
c71fe99… wyoung 455
c71fe99… wyoung 456 This work is far easier when each cherry-pick transfers completely and
c71fe99… wyoung 457 cleanly from one branch to another, and we increase the likelihood of
c71fe99… wyoung 458 achieving that state by working from the smallest check-ins that remain
c71fe99… wyoung 459 complete. If a support organization must manually disentangle a fix from
c71fe99… wyoung 460 a feature check-in, they are likely to introduce new bugs on the stable
c71fe99… wyoung 461 branch. Even if they manage to do their work without error, it takes
c71fe99… wyoung 462 them more time to do the cherry-pick that way.
c71fe99… wyoung 463
c71fe99… wyoung 464 [rh]: https://en.wikipedia.org/wiki/Red_Hat
c71fe99… wyoung 465
93cee1f… wyoung 466 ### <a id="backouts"></a>6.5 Back-outs also work better with small check-ins
c71fe99… wyoung 467
c71fe99… wyoung 468 The inverse of the cherry-pick merge is the back-out merge. If you push
c71fe99… wyoung 469 only a collapsed version of a private working branch up to the parent
c71fe99… wyoung 470 repo, those working from that parent repo cannot automatically back out
c71fe99… wyoung 471 any of the individual check-ins that went into that private branch.
c71fe99… wyoung 472 Others must either manually disentangle the problematic part of your
c71fe99… wyoung 473 merge check-in or back out the entire feature.
c71fe99… wyoung 474
93cee1f… wyoung 475 ## <a id="better-plan"></a>7.0 Cherry-pick merges work better than rebase
82f7586… drh 476
82f7586… drh 477 Perhaps there are some cases where a rebase-like transformation
5a7cda5… wyoung 478 is actually helpful, but those cases are rare, and when they do
5a7cda5… wyoung 479 come up, running a series of cherry-pick merges achieves the same
5a7cda5… wyoung 480 topology with several advantages:
5a7cda5… wyoung 481
068e26a… wyoung 482 1. In Fossil, cherry-pick merges preserve an honest and clear record
068e26a… wyoung 483 of history. Fossil remembers where a cherry-pick came from, and
068e26a… wyoung 484 it shows this in its timeline, so other developers can understand
068e26a… wyoung 485 how a cherry-pick based commit came together.
068e26a… wyoung 486
068e26a… wyoung 487 Git lacks the ability to remember the source of a cherry-pick as
068e26a… wyoung 488 part of the commit. This fact has no direct bearing on this
068e26a… wyoung 489 document’s thesis, but we can make a few observations. First, Git
068e26a… wyoung 490 forgets history in more cases than in rebasing. Second, if Git
068e26a… wyoung 491 remembered the source of cherry-picks in commits, Git users might
068e26a… wyoung 492 have a better argument for avoiding rebase, because they’d have an
068e26a… wyoung 493 alternative that *didn’t* lose history.
068e26a… wyoung 494
068e26a… wyoung 495 2. Fossil’s [test before commit philosophy][tbc] means you can test a
068e26a… wyoung 496 cherry-pick before committing it. Because Fossil allows multiple
068e26a… wyoung 497 cherry-picks in a single commit and it remembers them all, you can
068e26a… wyoung 498 do this for a complicated merge in step-wise fashion.
068e26a… wyoung 499
068e26a… wyoung 500 Git commits cherry-picks straight to the repository, so that if it
068e26a… wyoung 501 results in a bad state, you have to do something drastic like
068e26a… wyoung 502 `git reset --hard` to repair the damage.
068e26a… wyoung 503
068e26a… wyoung 504 3. Cherry-picks keep both the original and the revised check-ins,
4f79941… drh 505 so both timestamps are preserved.
4f79941… drh 506
c71fe99… wyoung 507 [tbc]: ./fossil-v-git.wiki#testing
c71fe99… wyoung 508
93cee1f… wyoung 509 ## <a id="conclusion"></a>8.0 Summary and conclusion
4f79941… drh 510
4f79941… drh 511 Rebasing is an anti-pattern. It is dishonest. It deliberately
4f79941… drh 512 omits historical information. It causes problems for collaboration.
4f79941… drh 513 And it has no offsetting benefits.
4f79941… drh 514
4f79941… drh 515 For these reasons, rebase is intentionally and deliberately omitted
4f79941… drh 516 from the design of Fossil.
4f79941… drh 517
4f79941… drh 518
4f79941… drh 519 [golden]: https://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing
4f79941… drh 520 [gitrebase]: https://git-scm.com/book/en/v2/Git-Branching-Rebasing
4f79941… drh 521 [nagappan]: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/tr-2008-11.pdf
4f79941… drh 522 [weinberg]: https://books.google.com/books?id=76dIAAAAMAAJ

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button