Slide 1

Slide 1 text

Git Graphs, Hashes, and Compression, Oh My! © 2012, GitHub, Inc.

Slide 2

Slide 2 text

[email protected] github.com/training @matthewmccull matthewmccullough

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

GIT - the stupid content tracker "git" can mean anything, depending on your mood. * random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant. * stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang. * "global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room. * "goddamn idiotic truckload of sh*t": when it breaks Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals. Git is an Open Source project covered by the GNU General Public License. It was originally written by Linus Torvalds with help of a group of hackers around the net. It is currently maintained by Junio C Hamano. “ ”

Slide 6

Slide 6 text

2005 git

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Architecture Hashes

Slide 10

Slide 10 text

centralized VCSs use sequential revision numbers

Slide 11

Slide 11 text

Git uses a SHA-1 hash

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

40 hex characters (20 bytes)

Slide 14

Slide 14 text

9AB223D28B1AA46EF1780B22F304982E39872C34

Slide 15

Slide 15 text

9AB223D28B1AA46EF1780B22F304982E39872C34

This is a test

9AB223D28B1AA46EF1780B22F304982E39872C34

Slide 16

Slide 16 text

Hashed Content Git commits without Git

Slide 17

Slide 17 text

# Green field project $ git init newproject $ cd newproject # ...start coding

Slide 18

Slide 18 text

.git !"" COMMIT_EDITMSG !"" HEAD !"" MERGE_RR !"" config !"" description !"" hooks # !"" pre-commit.sample # $"" update.sample !"" index !"" info # $"" exclude !"" logs # !"" HEAD # $"" refs # $"" heads # $"" master !"" objects # !"" 54 # # $"" 3b9bebdc6bd5c4b22136034a95dd097a57d3dd # !"" info # $"" pack !"" refs !"" heads # $"" master $"" tags

Slide 19

Slide 19 text

$ printf "blob 12\000Hello World\n" | shasum

Slide 20

Slide 20 text

Architecture Hash Shortcuts

Slide 21

Slide 21 text

use as little of it as is unique

Slide 22

Slide 22 text

9AB223D28B1AA46EF 1780B22F304982E39 872C34 a certain commit

Slide 23

Slide 23 text

9AB22F a certain commit

Slide 24

Slide 24 text

git rev-parse 9AB22F expand the commit ref

Slide 25

Slide 25 text

Architecture Storage

Slide 26

Slide 26 text

Typical SCMs use delta storage

Slide 27

Slide 27 text

CVS / Subversion / darcs / Mercurial

Slide 28

Slide 28 text

v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File B File B Δ Δ Δ Δ Δ Δ Δ

Slide 29

Slide 29 text

Checkin Checkin Checkin Checkin Checkin Checkin Checkin Checkin Checkin Checkin Checkin Delta storage gets slower as the history of a file gets longer

Slide 30

Slide 30 text

Directed Acyclic Graph

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Copy of the entire tree per checkin

Slide 33

Slide 33 text

cp -r srcfolder srcfolder.prev

Slide 34

Slide 34 text

Why?

Slide 35

Slide 35 text

v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File B File B File A File A File C File C File C

Slide 36

Slide 36 text

hard link to existing identical blobs

Slide 37

Slide 37 text

v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File B File B File A File A File C File C File C ß

Slide 38

Slide 38 text

zlib deflates each blob at commit

Slide 39

Slide 39 text

v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File B File B File A File A File C File C File C

Slide 40

Slide 40 text

zlib deflates the entire repo

Slide 41

Slide 41 text

v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File B File B File A File A File C File C File C

Slide 42

Slide 42 text

2100 MB became 205 MB Act I

Slide 43

Slide 43 text

Architecture Hash relationships

Slide 44

Slide 44 text

‣Blob ‣Tree ‣Commit ‣Tag

Slide 45

Slide 45 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 46

Slide 46 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 47

Slide 47 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 48

Slide 48 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 49

Slide 49 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 50

Slide 50 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 51

Slide 51 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 52

Slide 52 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 53

Slide 53 text

tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1 commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162

Slide 54

Slide 54 text

v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7

Slide 55

Slide 55 text

v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7

Slide 56

Slide 56 text

v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7

Slide 57

Slide 57 text

v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7

Slide 58

Slide 58 text

v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7

Slide 59

Slide 59 text

v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7

Slide 60

Slide 60 text

v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7

Slide 61

Slide 61 text

v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7

Slide 62

Slide 62 text

RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1

Slide 63

Slide 63 text

RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1

Slide 64

Slide 64 text

RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1

Slide 65

Slide 65 text

RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1

Slide 66

Slide 66 text

RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1

Slide 67

Slide 67 text

RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1

Slide 68

Slide 68 text

Architecture Hash shortcuts

Slide 69

Slide 69 text

commitish & treeish

Slide 70

Slide 70 text

commitish = shorthand for commit hashes

Slide 71

Slide 71 text

treeish = shorthand for tree hashes

Slide 72

Slide 72 text

9AB22F a certain commit

Slide 73

Slide 73 text

9AB22F^ one commit before a certain commit

Slide 74

Slide 74 text

9AB22F^^ two commits before a certain commit

Slide 75

Slide 75 text

9AB22F~5 five commits before a certain commit

Slide 76

Slide 76 text

9AB223..56CD77 between these two commits

Slide 77

Slide 77 text

HEAD the most recent commit on this branch

Slide 78

Slide 78 text

HEAD^ one commit before the most recent commit

Slide 79

Slide 79 text

HEAD~2 two commits before the most recent commit

Slide 80

Slide 80 text

HEAD..HEAD^^^ between the given recent commits

Slide 81

Slide 81 text

master the most recent commit on this branch

Slide 82

Slide 82 text

master^^ two commits before the most recent commit on this branch

Slide 83

Slide 83 text

master~5 five commits before the most recent commit on this branch

Slide 84

Slide 84 text

remotes/origin/master the most recent commit on this remote tracking branch

Slide 85

Slide 85 text

origin/master the most recent commit on this remote tracking branch

Slide 86

Slide 86 text

The Graph Verification

Slide 87

Slide 87 text

git fsck

Slide 88

Slide 88 text

git verify-pack -v .git/objects/pack/FILENAME

Slide 89

Slide 89 text

The Graph More graph navigation

Slide 90

Slide 90 text

master^{tree} find this commit’s tree

Slide 91

Slide 91 text

git describe HASH find nearest tag

Slide 92

Slide 92 text

:/some words commit message that starts with

Slide 93

Slide 93 text

REF:FILE blob spec

Slide 94

Slide 94 text

:0:FILE index

Slide 95

Slide 95 text

:1:FILE common ancestor

Slide 96

Slide 96 text

:2:FILE target

Slide 97

Slide 97 text

:3:FILE merging in

Slide 98

Slide 98 text

The Wrap

Slide 99

Slide 99 text

[email protected] github.com/training @matthewmccull matthewmccullough

Slide 100

Slide 100 text

Git Graphs, Hashes, and Compression, Oh My! © 2012, GitHub, Inc.