├── .gitignore
└── gitfromtheinsideout
├── diagrams.graffle
├── images
├── 24-13.png
├── 7-a2.png
├── 3-a1-refs.png
├── 2-a1-commit.png
├── 26-14-bravo.png
├── 30-16-alpha.png
├── 1-a1-tree-graph.png
├── 11-a3-on-deputy.png
├── 13-a3ondeputy.png
├── 15-a3-on-master.png
├── 18-b4-on-deputy.png
├── 19-b6-on-master.png
├── 21-b13-on-master.png
├── 4-a1-wc-and-index.png
├── 10-a3-detached-head.png
├── 16-a4-b3-on-deputy.png
├── 17-a4-b3-on-deputy.png
├── 9-a2-detached-head.png
├── 12-a3-on-master-on-a2.png
├── 14-a3-on-master-on-a2.png
├── 27-14-fetched-to-alpha.png
├── 28-14-merged-to-alpha.png
├── 31-16-pushed-to-delta.png
├── 25-13-cp-alpha-to-bravo.png
├── 5-a1-wc-number-set-to-2.png
├── 20-b6-on-master-with-merge-head.png
├── 22-b13-with-objects-wc-and-index.png
├── 29-15-alpha-cloned-to-delta-bare.png
├── 6-a1-wc-and-index-number-set-to-2.png
├── 8-a2-just-objects-commits-and-refs.png
└── 23-b13-letter-removed-from-wc-and-index.png
└── essay.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
--------------------------------------------------------------------------------
/gitfromtheinsideout/diagrams.graffle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/diagrams.graffle
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/24-13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/24-13.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/7-a2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/7-a2.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/3-a1-refs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/3-a1-refs.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/2-a1-commit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/2-a1-commit.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/26-14-bravo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/26-14-bravo.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/30-16-alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/30-16-alpha.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/1-a1-tree-graph.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/1-a1-tree-graph.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/11-a3-on-deputy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/11-a3-on-deputy.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/13-a3ondeputy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/13-a3ondeputy.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/15-a3-on-master.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/15-a3-on-master.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/18-b4-on-deputy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/18-b4-on-deputy.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/19-b6-on-master.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/19-b6-on-master.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/21-b13-on-master.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/21-b13-on-master.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/4-a1-wc-and-index.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/4-a1-wc-and-index.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/10-a3-detached-head.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/10-a3-detached-head.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/16-a4-b3-on-deputy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/16-a4-b3-on-deputy.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/17-a4-b3-on-deputy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/17-a4-b3-on-deputy.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/9-a2-detached-head.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/9-a2-detached-head.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/12-a3-on-master-on-a2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/12-a3-on-master-on-a2.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/14-a3-on-master-on-a2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/14-a3-on-master-on-a2.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/27-14-fetched-to-alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/27-14-fetched-to-alpha.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/28-14-merged-to-alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/28-14-merged-to-alpha.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/31-16-pushed-to-delta.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/31-16-pushed-to-delta.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/25-13-cp-alpha-to-bravo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/25-13-cp-alpha-to-bravo.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/5-a1-wc-number-set-to-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/5-a1-wc-number-set-to-2.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/20-b6-on-master-with-merge-head.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/20-b6-on-master-with-merge-head.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/22-b13-with-objects-wc-and-index.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/22-b13-with-objects-wc-and-index.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/29-15-alpha-cloned-to-delta-bare.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/29-15-alpha-cloned-to-delta-bare.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/6-a1-wc-and-index-number-set-to-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/6-a1-wc-and-index-number-set-to-2.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/8-a2-just-objects-commits-and-refs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/8-a2-just-objects-commits-and-refs.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/images/23-b13-letter-removed-from-wc-and-index.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maryrosecook/DEPRECATED-essays/HEAD/gitfromtheinsideout/images/23-b13-letter-removed-from-wc-and-index.png
--------------------------------------------------------------------------------
/gitfromtheinsideout/essay.md:
--------------------------------------------------------------------------------
1 | Hi everyone. Thanks for visiting. This content is a draft. The final version of the essay (complete with working images) is here: https://codewords.recurse.com/issues/two/git-from-the-inside-out
2 |
3 | ---------------------------------------------
4 |
5 | # Git from the inside out
6 |
7 | This essay shows you how Git works. It focuses on the graph that underpins Git and how the properties of this graph dictate the behaviors of Git. This focus on fundamentals lets you build your mental model on the truth, rather than on hypotheses constructed from evidence gathered while experimenting with the API. This truer model gives you a better understanding of what Git has done, what it is doing and what it will do.
8 |
9 | The text is structured as a series of Git commands run on a single project. At intervals, there are observations about the graph data structure that Git is built on. These observations illustrate a property of the graph and the behavior that this property produces.
10 |
11 | It is assumed that you understand Git well enough to use it to version control your projects.
12 |
13 | ## Create a project
14 |
15 | ```bash
16 | ~ $ mkdir alpha
17 | ~ $ cd alpha
18 | ```
19 |
20 | The user creates `alpha`, a directory for their project.
21 |
22 | ```bash
23 | ~/alpha $ mkdir data
24 | ~/alpha $ printf 'a' > data/letter.txt
25 | ```
26 |
27 | They move into the `alpha` directory and create a directory called `data`. Inside, they create a file called `letter.txt` that contains `a`. The alpha directory looks like this:
28 |
29 | ```
30 | alpha
31 | └── data
32 | └── letter.txt
33 | ```
34 |
35 | # Initialize a repository
36 |
37 | ```bash
38 | ~/alpha $ git init
39 | Initialized empty Git repository
40 | ```
41 |
42 | `git init` turns the current directory into a Git repository. To do this, it creates a `.git` directory and writes some files to it. These files define everything about the configuration and history of a project. They are just ordinary files. No magic in them. The user can read and change them with a text editor or shell. Which is to say: the user can read and edit the history of their project as easily as their project files.
43 |
44 | The `alpha` directory now looks like this:
45 |
46 | ```
47 | alpha
48 | ├── data
49 | | └── letter.txt
50 | └── .git
51 | ├── objects
52 | etc...
53 | ```
54 |
55 |
56 | The `.git` directory and its contents are Git's. All the other files are collectively known as the working copy. They are the user's.
57 |
58 | ## Add some files
59 |
60 | ```
61 | ~/alpha $ git add data/letter.txt
62 | ```
63 |
64 | The user runs `git add` on the `data/letter.txt` file. This has two effects.
65 |
66 | First, it creates a new blob file in the directory at `alpha/.git/objects/`.
67 |
68 | This file contains the compressed content of the `data/letter.txt` file.
69 |
70 | The name of this file is derived by hashing the file's content. Hashing a piece of text means running a program on it that turns it into a smaller[^1] piece of text that uniquely[^2] identifies the original. For example, Git hashes `a` to `5e40c0877058c504203932e5136051cf3cd3519b`. This hash is a short, unique identifier for the current content of `number.txt`. The first two characters are used as the name of a directory inside `alpha/.git/objects/`: `5e`. The rest of the hash is used as the name of the file that holds the content of added file: `40c0877058c504203932e5136051cf3cd3519b`.
71 |
72 | Notice how just adding a file to Git saves its content to the objects directory. If the user were to delete the `data/letter.txt` file the working copy, its content would still be safe inside Git.
73 |
74 | Second, `git add` adds the file to the index. The index is a list that contains every file that Git has been told to keep track of. It is just a file that lives at `alpha/.git/index`. Each line of the file maps a tracked file to a hash of its content at the moment it was added.
75 |
76 | ```
77 | data/letter.txt 5e40c0877058c504203932e5136051cf3cd3519b
78 | ```
79 |
80 | ```bash
81 | ~/alpha $ printf '1234' > data/number.txt
82 | ```
83 |
84 | The user makes a file called `data/number.txt` that contains `1234`. The working copy looks like this:
85 |
86 | ```text
87 | alpha
88 | └── data
89 | └── letter.txt
90 | └── number.txt
91 | ```
92 |
93 | ```bash
94 | ~/alpha $ git add data
95 | ```
96 |
97 | The user adds the file to Git. This creates a blob file that contains the content of `data/number.txt`. And it adds another index entry that maps the `data/number.txt` file to a hash of its content.
98 |
99 | ```
100 | data/letter.txt 5e40c0877058c504203932e5136051cf3cd3519b
101 | data/number.txt 274c0052dd5408f8ae2bc8440029ff67d79bc5c3
102 | ```
103 |
104 | Note that, though the user ran `git add data`, only the files in the `data` directory are listed. The `data` directory is not listed separately.
105 |
106 | ```bash
107 | ~/alpha $ printf '1' > data/number.txt
108 | ~/alpha $ git add data
109 | ```
110 |
111 | When the user originally created `data/number.txt`, they meant to type `1`, not `1234`. They make the correction and add the file to the index again. This creates a new blob with the new content. It updates the index entry for `data/number.txt` so it maps to the hash of the latest content.
112 |
113 | ## Make a commit
114 |
115 | ```bash
116 | ~/alpha $ git commit -m 'a1'
117 | [master (root-commit) c388d51] a1
118 | ```
119 |
120 | Committing has three steps. It creates a tree graph to represent the content of the version being committed. It creates a commit object. It pointsthe current branch at the new commit object.
121 |
122 | ### Create a tree graph
123 |
124 | Git records the current state of the project by creating a tree graph from the index. This tree graph records the location and content of every file in the project.
125 |
126 | The graph is composed of two types of object: blobs and trees.
127 |
128 | Blobs are stored by `git add`. They represent the content of files.
129 |
130 | Trees are stored when a commit is made. A tree represents a directory in the working copy. It has one line for each item in the directory. An item might be a file or another directory. Each line records the four things required to reproduce the item in the project. The item's permissions. The type of object (blob or tree) that represents the item. The hash of the object. The name of the item.
131 |
132 | Below is the tree object that records the state of the `data` directory for the current commit. It has entries for the `number.txt` and `letter.txt` files. Notice that the entries use hashes to point at the blob objects that represent their content.
133 |
134 | ```
135 | 100664 blob 5e40c0877058c504203932e5136051cf3cd3519b letter.txt
136 | 100664 blob 274c0052dd5408f8ae2bc8440029ff67d79bc5c3 number.txt
137 | ```
138 |
139 | Below is the tree object for `alpha`, the root directory of the project. It has a line that points at the `data` tree.
140 |
141 | ```
142 | 040000 tree 0eed1217a2947f4930583229987d90fe5e8e0b74 data
143 | ```
144 |
145 | The tree graph is built from the index. The index only contains files, not directories. This means that empty directories will not appear in tree graphs. This is what people mean when they say, "Git only tracks files."
146 |
147 |
148 |
167 |
186 |
195 |
206 |
215 |
255 |
258 |
306 |
320 |
337 |
365 |
392 |
415 |
427 |
454 |
474 |
511 |
536 |
550 |
612 |
619 |
633 |
643 |
668 |
699 |
726 |
743 |
817 |
838 |
856 |