git graphs, hashes, and compression, oh my

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

Upload: matthew-mccullough

Post on 12-Apr-2017

392 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Git Graphs, Hashes, and Compression, Oh My

at                                                        with  Matthew  McCullough

GitGraphs, Hashes, and Compression, Oh My!

© 2

012,

GitH

ub, I

nc.

Page 3: Git Graphs, Hashes, and Compression, Oh My
Page 4: Git Graphs, Hashes, and Compression, Oh My
Page 5: Git Graphs, Hashes, and Compression, Oh My

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. contempti

ble and despicable. simple. Take your

pick from the dictionary of

slang.* "global informati

on tracker": you're in a good mood, an

d it actually works for you.

Angels sing, and a light suddenly fill

s the room.

* "goddamn idiotic truckload of sh*t":

when it breaks

Git is a fast, scalable, distributed r

evision control system with an unusual

ly rich

command set that provides both high-le

vel operations and full access to inte

rnals.

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.

Page 6: Git Graphs, Hashes, and Compression, Oh My

2005git

Page 7: Git Graphs, Hashes, and Compression, Oh My

ArchitectureHashes

Page 8: Git Graphs, Hashes, and Compression, Oh My

centralized VCSs use sequential revision numbers

Page 9: Git Graphs, Hashes, and Compression, Oh My

Git uses a SHA-1 hash

Page 10: Git Graphs, Hashes, and Compression, Oh My
Page 11: Git Graphs, Hashes, and Compression, Oh My

40 hex characters (20 bytes)

Page 12: Git Graphs, Hashes, and Compression, Oh My

9AB223D28B1AA46EF1780B22F304982E39872C34

Page 13: Git Graphs, Hashes, and Compression, Oh My

9AB223D28B1AA46EF1780B22F304982E39872C34

<html><body>

<p>This is a test</p><img src="http://ai.com/icon.gif">

</body></html>

Page 14: Git Graphs, Hashes, and Compression, Oh My

<html><body>

<p>This is a test</p><img src="http://ai.com/icon.gif">

</body></html>

9AB223D28B1AA46EF1780B22F304982E39872C34

Page 15: Git Graphs, Hashes, and Compression, Oh My

Hashed ContentGit commits without Git

Page 16: Git Graphs, Hashes, and Compression, Oh My

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

Page 17: Git Graphs, Hashes, and Compression, Oh My

.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

Page 18: Git Graphs, Hashes, and Compression, Oh My

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

Page 19: Git Graphs, Hashes, and Compression, Oh My

ArchitectureHash Shortcuts

Page 20: Git Graphs, Hashes, and Compression, Oh My

use as little of it as is unique

Page 21: Git Graphs, Hashes, and Compression, Oh My

9AB223D28B1AA46EF1780B22F304982E39

872C34a certain commit

Page 22: Git Graphs, Hashes, and Compression, Oh My

9AB22Fa certain commit

Page 23: Git Graphs, Hashes, and Compression, Oh My

git rev-parse 9AB22Fexpand the commit ref

Page 24: Git Graphs, Hashes, and Compression, Oh My

ArchitectureStorage

Page 25: Git Graphs, Hashes, and Compression, Oh My

Typical SCMs use delta storage

Page 26: Git Graphs, Hashes, and Compression, Oh My

CVS / Subversion / darcs / Mercurial

Page 27: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

Page 28: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

Δ Δ

ΔΔ ΔΔΔ

Page 29: Git Graphs, Hashes, and Compression, Oh My
Page 30: Git Graphs, Hashes, and Compression, Oh My

Checkin

Checkin Checkin Che

ckin

Che

ckin

Che

ckin

Che

ckin

Che

ckin

Check

in

Checkin

Checkin

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

Page 31: Git Graphs, Hashes, and Compression, Oh My

Directed Acyclic Graph

Page 32: Git Graphs, Hashes, and Compression, Oh My
Page 33: Git Graphs, Hashes, and Compression, Oh My

Copy of the entire tree per checkin

Page 34: Git Graphs, Hashes, and Compression, Oh My

cp -r srcfolder srcfolder.prev

Page 35: Git Graphs, Hashes, and Compression, Oh My

Why?

Page 36: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

File A File A

File C File C File C

Page 37: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

File A File A

File C File C File C

Page 38: Git Graphs, Hashes, and Compression, Oh My

hard link to existing identical blobs

Page 39: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

File A File A

File C File C File C

Page 40: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

File A File A

File C File C File Cß

Page 41: Git Graphs, Hashes, and Compression, Oh My

zlib deflates each blob at commit

Page 42: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

File A File A

File C File C File C

Page 43: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

File A File A

File C File C File C

Page 44: Git Graphs, Hashes, and Compression, Oh My

zlib deflates the entire repo

Page 45: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

File A File A

File C File C File C

Page 46: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3 v4

File A

File B

File C

File A

File B File B

File C

v5

File A

File BFile B

File A File A

File C File C File C

Page 47: Git Graphs, Hashes, and Compression, Oh My

2100 MB became 205 MB

Act I

Page 48: Git Graphs, Hashes, and Compression, Oh My

ArchitectureHash relationships

Page 49: Git Graphs, Hashes, and Compression, Oh My

‣Blob‣Tree‣Commit‣Tag

Page 50: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 51: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 52: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 53: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 54: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 55: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 56: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 57: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 58: Git Graphs, Hashes, and Compression, Oh My

treetree: 7e8b1 webblob: 9ab16 index.html

a10b3 treeblob: 8d162 logo.jpgblob: 51d22 draw.js

7e8b1commit

tree: a10b3parent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the web content.

c67db

blob<html>

<body></body></html>

9ab16

blob//Some more javascriptvar renderSize

51d22

blob7D 8D B3 7F BD 12 9F E97B 78 9D 3F 5C A6 72 CB

8d162

Page 59: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3

committree: 9a87bparent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the Javascript renderingengine.

c67db

committree: b22c1parent: c67dbauthor: Timcommitter: Firdmessage:

Minor update to HTML

9bd21

committree: b22c1parent: 9bd21author: Johnnycommitter: Joemessage:

New language transations

1c2d7

Page 60: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3

committree: 9a87bparent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the Javascript renderingengine.

c67db

committree: b22c1parent: c67dbauthor: Timcommitter: Firdmessage:

Minor update to HTML

9bd21

committree: b22c1parent: 9bd21author: Johnnycommitter: Joemessage:

New language transations

1c2d7

Page 61: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3

committree: 9a87bparent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the Javascript renderingengine.

c67db

committree: b22c1parent: c67dbauthor: Timcommitter: Firdmessage:

Minor update to HTML

9bd21

committree: b22c1parent: 9bd21author: Johnnycommitter: Joemessage:

New language transations

1c2d7

Page 62: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3

committree: 9a87bparent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the Javascript renderingengine.

c67db

committree: b22c1parent: c67dbauthor: Timcommitter: Firdmessage:

Minor update to HTML

9bd21

committree: b22c1parent: 9bd21author: Johnnycommitter: Joemessage:

New language transations

1c2d7

Page 63: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3

committree: 9a87bparent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the Javascript renderingengine.

c67db

committree: b22c1parent: c67dbauthor: Timcommitter: Firdmessage:

Minor update to HTML

9bd21

committree: b22c1parent: 9bd21author: Johnnycommitter: Joemessage:

New language transations

1c2d7

Page 64: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3

committree: 9a87bparent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the Javascript renderingengine.

c67db

committree: b22c1parent: c67dbauthor: Timcommitter: Firdmessage:

Minor update to HTML

9bd21

committree: b22c1parent: 9bd21author: Johnnycommitter: Joemessage:

New language transations

1c2d7

Page 65: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3

committree: 9a87bparent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the Javascript renderingengine.

c67db

committree: b22c1parent: c67dbauthor: Timcommitter: Firdmessage:

Minor update to HTML

9bd21

committree: b22c1parent: 9bd21author: Johnnycommitter: Joemessage:

New language transations

1c2d7

Page 66: Git Graphs, Hashes, and Compression, Oh My

v1 v2 v3

committree: 9a87bparent: nilauthor: Firdcommitter: Matthewmessage:

Major refactoringof the Javascript renderingengine.

c67db

committree: b22c1parent: c67dbauthor: Timcommitter: Firdmessage:

Minor update to HTML

9bd21

committree: b22c1parent: 9bd21author: Johnnycommitter: Joemessage:

New language transations

1c2d7

Page 67: Git Graphs, Hashes, and Compression, Oh My

RELEASE_1.0 HEAD

bug979branch

commitc67db

commit9bd21

commit1c2d7

commit8c2d1

commit1bdcd

commit2daa1

Page 68: Git Graphs, Hashes, and Compression, Oh My

RELEASE_1.0 HEAD

bug979branch

commitc67db

commit9bd21

commit1c2d7

commit8c2d1

commit1bdcd

commit2daa1

Page 69: Git Graphs, Hashes, and Compression, Oh My

RELEASE_1.0 HEAD

bug979branch

commitc67db

commit9bd21

commit1c2d7

commit8c2d1

commit1bdcd

commit2daa1

Page 70: Git Graphs, Hashes, and Compression, Oh My

RELEASE_1.0 HEAD

bug979branch

commitc67db

commit9bd21

commit1c2d7

commit8c2d1

commit1bdcd

commit2daa1

Page 71: Git Graphs, Hashes, and Compression, Oh My

RELEASE_1.0 HEAD

bug979branch

commitc67db

commit9bd21

commit1c2d7

commit8c2d1

commit1bdcd

commit2daa1

Page 72: Git Graphs, Hashes, and Compression, Oh My

RELEASE_1.0 HEAD

bug979branch

commitc67db

commit9bd21

commit1c2d7

commit8c2d1

commit1bdcd

commit2daa1

Page 73: Git Graphs, Hashes, and Compression, Oh My

ArchitectureHash shortcuts

Page 74: Git Graphs, Hashes, and Compression, Oh My

commitish & treeish

Page 75: Git Graphs, Hashes, and Compression, Oh My

commitish = shorthand for commit hashes

Page 76: Git Graphs, Hashes, and Compression, Oh My

treeish = shorthand for tree hashes

Page 77: Git Graphs, Hashes, and Compression, Oh My

9AB22Fa certain commit

Page 78: Git Graphs, Hashes, and Compression, Oh My

9AB22F^one commit before a certain commit

Page 79: Git Graphs, Hashes, and Compression, Oh My

9AB22F^^two commits before a certain commit

Page 80: Git Graphs, Hashes, and Compression, Oh My

9AB22F~5five commits before a certain commit

Page 81: Git Graphs, Hashes, and Compression, Oh My

9AB223..56CD77between these two commits

Page 82: Git Graphs, Hashes, and Compression, Oh My

HEADthe most recent commit on this branch

Page 83: Git Graphs, Hashes, and Compression, Oh My

HEAD^one commit before the most recent commit

Page 84: Git Graphs, Hashes, and Compression, Oh My

HEAD~2two commits before the most recent commit

Page 85: Git Graphs, Hashes, and Compression, Oh My

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

Page 86: Git Graphs, Hashes, and Compression, Oh My

masterthe most recent commit on this branch

Page 87: Git Graphs, Hashes, and Compression, Oh My

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

Page 88: Git Graphs, Hashes, and Compression, Oh My

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

Page 89: Git Graphs, Hashes, and Compression, Oh My

remotes/origin/masterthe most recent commit on this remote tracking branch

Page 90: Git Graphs, Hashes, and Compression, Oh My

origin/masterthe most recent commit on this remote tracking branch

Page 91: Git Graphs, Hashes, and Compression, Oh My

The GraphVerification

Page 92: Git Graphs, Hashes, and Compression, Oh My

git fsck

Page 93: Git Graphs, Hashes, and Compression, Oh My

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

Page 94: Git Graphs, Hashes, and Compression, Oh My

The GraphMore graph navigation

Page 95: Git Graphs, Hashes, and Compression, Oh My

master^{tree}find this commit’s tree

Page 96: Git Graphs, Hashes, and Compression, Oh My

git describe HASHfind nearest tag

Page 97: Git Graphs, Hashes, and Compression, Oh My

:/some wordscommit message that starts with

Page 98: Git Graphs, Hashes, and Compression, Oh My

REF:FILEblob spec

Page 99: Git Graphs, Hashes, and Compression, Oh My

:0:FILEindex

Page 100: Git Graphs, Hashes, and Compression, Oh My

:1:FILEcommon ancestor

Page 101: Git Graphs, Hashes, and Compression, Oh My

:2:FILEtarget

Page 102: Git Graphs, Hashes, and Compression, Oh My

:3:FILEmerging in

Page 104: Git Graphs, Hashes, and Compression, Oh My

at                                                        with  Matthew  McCullough

GitGraphs, Hashes, and Compression, Oh My!

© 2

012,

GitH

ub, I

nc.