summaryrefslogtreecommitdiff
path: root/git_rebase_illustrated_with_time_travel.html
blob: 0b7d4c61e4c1d94e1e3ced8e56a91104bebb381c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="aki">
<meta name="tags" content="git, rebase, branching, guide, time travel">
<meta name="published-on" content="2022-01-28T16:43:00+01:00">
<link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" href="style.css">

<title>Git Rebase Illustrated With Time Travel</title>

<header>
<nav><a href="https://ignore.pl">ignore.pl</a></nav>
<time>28 January 2022</time>
<h1>Git Rebase Illustrated With Time Travel</h1>
</header>

<article>
<p>Back in the office days, colleagues and I would have weekly discussions about git which usually ended with comparing
merge to rebase or with me preaching about the dangers of rewriting the history. Let's go back to these times but with
a slight twist. There's already plenty of other in-depth git tutorials and <b>git-rebase</b>(1) is great and you should
read it. There is no point in creating yet another resource, so instead let's make it a fun and chill weekend read.
<p>Let's say two different people are working on two completely disconnected task in parallel in a known period. These
tasks can be divided into a sequence of sub-tasks, where each sub-tasks enables next sub-task to be performed and there
is no room for parallelization (for now). This situation can be illustrated like this:</p>
<img src="git_rebase_illustrated_with_time_travel-1.png" alt="original timeline">
<p>In the graph <strong>A</strong> and <strong>B</strong> lanes represent the progress of a task with significant points
in sub-tasks. All sub-tasks can be projected into the time line and their order remains the same.
<p>Let's expand the example by adding two common spots in time for both tasks: first being someone ordering to perform
both tasks, and second being the merge of both lanes into one.</p>
<img src="git_rebase_illustrated_with_time_travel-2.png" alt="timeline with common tasks">
<p>This should look somehow similar to you, because (if not for the missing middle part) this graph represents a regular
workflow that uses <b>git-merge</b>(1). <strong>C</strong> is a common origin and goal for both task lanes and serves
the same purpose as <code>master</code> branch.
<p>In order to reduce the number of lanes we can let one of the tasks claim the main lane for their own. This happens
when you branch off an active branch that gets some additional work done before you merge back into it:</p>
<img src="git_rebase_illustrated_with_time_travel-3.png" alt="branch off and back">
<p>This image was probably recognized by you right away.
<p>Now, it just happened, but turns out that by the end of the <strong>A</strong> task the person responsible for it
built a time machine and proposed to the project management to use it in order to perform both tasks sequentially but in
parallel time. They were as confused as you are but gave green light just to see what happens.
<p>Developer took the results of <strong>B</strong> with them and went back in time to the spot where <strong>A</strong>
and <strong>B</strong> diverged. They started to work on <strong>A</strong> using the souvenir from the future as the
<em>base</em>. People that were working on task <strong>B</strong> in the meantime were confused.
<p>When the moment for merge came, the traveller from future just presented their work and said that it's already
merged, so there's no need to do anything. And they spoke truthfully, because in linear time the work looked like this:
</p>
<img src="git_rebase_illustrated_with_time_travel-4.png" alt="rebase in linear timeline">
<p>But from the perspective of the traveller the whole timeline got distorted and didn't look linear at all:</p>
<img src="git_rebase_illustrated_with_time_travel-5.png" alt="rebase in non-linear timeline">
<p>From this point of view the sequence is one-lane and completely undisturbed. On the other time the timeline gets
shifted and some parts of it fade away as they never were or are no longer observed by the time traveller. This is the
perspective that one assumes when explaining rebase "in a normal way": reapplying the changes to a different base code
(with same dates, meaning time travel, yay).
<p>All of this happens every time you rebase your branches. Really.
<p>Don't get me to talk started about interactive rebase features and cherry-picking! Or maybe do. That could be fun.
</article>
<script src="https://stats.ignore.pl/track.js"></script>