โ Back to How Git works inside
๐ธ How Git works inside: cheat sheet
๐จ The analogyA photo album where every photo is labelled with its fingerprint and each page points back to the one before.
๐ The regular explanationGit is a content-addressed store of immutable objects (blobs, trees, commits and tags) named by their hash, plus small movable refs such as branches and HEAD that point into the commit graph.
- You take a photo of one thing, a note saying hello. The fingerprint reader works out its fingerprint from exactly what is in the picture.
- The photo goes into the box, filed under its fingerprint. It has no name on it, only the picture.
- A second thing looks exactly the same. Same picture, same fingerprint, so the box doesn't keep a second copy.
- Next comes a contents card. It lists each photo by fingerprint and says what each one is called. The card gets a fingerprint of its own.
- Last comes the album page itself. It points to the card, says who made it and when, and has a caption. It gets a fingerprint too.
- The first page shows the whole project. Both photos go into the box, a note and a drawing.
- You change only the drawing. The new page still shows the whole project, but the note's photo is the same, so only the new drawing goes in the box.
- Want to know what changed? Lay page 1 and page 2 side by side and compare them. Nobody stored the change itself.
- The box gets crowded, so it's packed neatly. The second drawing is kept as the first one plus a small note about the difference.
- The album has two pages. The bookmark called main sits on the newest one, and the HEAD ribbon is tied to that bookmark.
- You change the drawing and put its new photo on the tray. Only what's on the tray goes onto the next page.
- You add a page from the tray. It points back to the page before, and the main bookmark moves onto it, taking the ribbon along.
- You lay the ribbon straight on an old page to look around. It isn't tied to any bookmark now, so stick one on before adding pages here.
- Ana's main bookmark is on page b7c. Ben and Cleo both started from that page and each added pages on their own line.
- Ben's turn. Main hasn't moved since he started, so Ana just slides her bookmark forward onto his newest page. No new page is made.
- Cleo's turn. Main has moved on and so has Cleo, so sliding isn't possible. Git compares both lines with the page they share, b7c.
- Git makes a new joining page that points back to two pages, Ben's c3d and Cleo's e5f. The main bookmark moves onto it.
- Ben's two pages start from b7c, but Ana's main has moved on to e5f. Ben's ribbon is on his newest page, d4e.
- Ben redoes his pages on top of e5f. Each copy points back to a different page, so it gets a new fingerprint, c9a and d8b.
- His bookmark and the ribbon jump to the copies. The old pages have no bookmark left, but the diary writes down where they were.
- If the copies went wrong, Ben looks up the old fingerprint in the diary and can put his bookmark straight back on d4e.
- Weeks later the diary entry is too old and gets crossed out. Now nothing reaches the old pages, so the tidy-up throws them away.
- Your album and the friend's copy both end at b7c. Your pencil bookmark, origin/main, says the friend's main was on b7c too.
- A teammate adds page c3d at the friend's house. Your pencil bookmark doesn't know, because you haven't visited since.
- Fetching means visiting, copying the new page into your box and moving your pencil bookmark. Your own main bookmark stays put.
- Pulling is fetching and then joining. Here main hasn't moved, so your bookmark simply slides forward onto c3d.
๐งฉ Key questions
- You change one drawing in a big project and add a new page. What new things go into the box?
- The new drawing's photo, new contents cards for it, and the page itself. Every page shows the whole project, but unchanged photos keep the same fingerprint, so the box keeps just one copy.
- Ben redid his pages on top of Ana's and now wishes he hadn't. His bookmark only shows the copies. Can he get the old pages back?
- Yes, the ribbon's diary still has the old fingerprint, so he can put his bookmark back on it. The old pages stay in the box until nothing, not even a diary entry, reaches them, and the tidy-up only throws out old ones.
- You visit the friend's house and copy the new pages, but you don't join them in. What moved in your album?
- Only your pencil bookmarks, like origin/main, and the new pages in the box. Fetching copies pages and updates the pencil bookmarks. Your own bookmarks only move when you join the new pages in, which is what pulling adds.
- You lay the ribbon straight on an old page, add two new pages there, then tie the ribbon back to main. What happens to the two new pages?
- They stay in the box, but no bookmark points at them; only the diary remembers where they are. No bookmark was on those pages, so they are hard to find. Stick a bookmark on first, or look them up in the diary soon.