Slide 1

Slide 1 text

at                                                        with  Matthew  McCullough Git Graphs, Hashes, and Compression, Oh My! © 2012, GitHub, Inc.

Slide 2

Slide 2 text

@matthewmccull [email protected] github.com/training

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

Architecture Hashes

Slide 8

Slide 8 text

centralized VCSs use sequential revision numbers

Slide 9

Slide 9 text

Git uses a SHA-1 hash

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

40 hex characters (20 bytes)

Slide 12

Slide 12 text

9AB223D28B1AA46EF1780B22F304982E39872C34

Slide 13

Slide 13 text

9AB223D28B1AA46EF1780B22F304982E39872C34

This is a test

Slide 14

Slide 14 text

This is a test

9AB223D28B1AA46EF1780B22F304982E39872C34

Slide 15

Slide 15 text

Hashed Content Git commits without Git

Slide 16

Slide 16 text

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

Slide 17

Slide 17 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 18

Slide 18 text

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

Slide 19

Slide 19 text

Architecture Hash Shortcuts

Slide 20

Slide 20 text

use as little of it as is unique

Slide 21

Slide 21 text

9AB223D28B1AA46EF 1780B22F304982E39 872C34 a certain commit

Slide 22

Slide 22 text

9AB22F a certain commit

Slide 23

Slide 23 text

git rev-parse 9AB22F expand the commit ref

Slide 24

Slide 24 text

Architecture Storage

Slide 25

Slide 25 text

Typical SCMs use delta storage

Slide 26

Slide 26 text

CVS / Subversion / darcs / Mercurial

Slide 27

Slide 27 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 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

No content

Slide 30

Slide 30 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 31

Slide 31 text

Directed Acyclic Graph

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Copy of the entire tree per checkin

Slide 34

Slide 34 text

cp -r srcfolder srcfolder.prev

Slide 35

Slide 35 text

Why?

Slide 36

Slide 36 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 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

hard link to existing identical blobs

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

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 41

Slide 41 text

zlib deflates each blob at commit

Slide 42

Slide 42 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 43

Slide 43 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 44

Slide 44 text

zlib deflates the entire repo

Slide 45

Slide 45 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 46

Slide 46 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 47

Slide 47 text

2100 MB became 205 MB Act I

Slide 48

Slide 48 text

Architecture Hash relationships

Slide 49

Slide 49 text

‣Blob ‣Tree ‣Commit ‣Tag

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

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 55

Slide 55 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 56

Slide 56 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 57

Slide 57 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 58

Slide 58 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 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

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 63

Slide 63 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 64

Slide 64 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 65

Slide 65 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 66

Slide 66 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 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

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

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

Slide 73

Slide 73 text

Architecture Hash shortcuts

Slide 74

Slide 74 text

commitish & treeish

Slide 75

Slide 75 text

commitish = shorthand for commit hashes

Slide 76

Slide 76 text

treeish = shorthand for tree hashes

Slide 77

Slide 77 text

9AB22F a certain commit

Slide 78

Slide 78 text

9AB22F^ one commit before a certain commit

Slide 79

Slide 79 text

9AB22F^^ two commits before a certain commit

Slide 80

Slide 80 text

9AB22F~5 five commits before a certain commit

Slide 81

Slide 81 text

9AB223..56CD77 between these two commits

Slide 82

Slide 82 text

HEAD the most recent commit on this branch

Slide 83

Slide 83 text

HEAD^ one commit before the most recent commit

Slide 84

Slide 84 text

HEAD~2 two commits before the most recent commit

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

master the most recent commit on this branch

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

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

Slide 91

Slide 91 text

The Graph Verification

Slide 92

Slide 92 text

git fsck

Slide 93

Slide 93 text

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

Slide 94

Slide 94 text

The Graph More graph navigation

Slide 95

Slide 95 text

master^{tree} find this commit’s tree

Slide 96

Slide 96 text

git describe HASH find nearest tag

Slide 97

Slide 97 text

:/some words commit message that starts with

Slide 98

Slide 98 text

REF:FILE blob spec

Slide 99

Slide 99 text

:0:FILE index

Slide 100

Slide 100 text

:1:FILE common ancestor

Slide 101

Slide 101 text

:2:FILE target

Slide 102

Slide 102 text

:3:FILE merging in

Slide 103

Slide 103 text

@matthewmccull [email protected] github.com/training

Slide 104

Slide 104 text

at                                                        with  Matthew  McCullough Git Graphs, Hashes, and Compression, Oh My! © 2012, GitHub, Inc.