Understanding Git Internals
Click here to load reader
-
Upload
jeff-kunkle -
Category
Technology
-
view
1.567 -
download
2
description
Transcript of Understanding Git Internals
GitJeff Kunkle
Understanding
January 6, 2010
Git is a free & open source, distributed version control system designed to handle everything from small to very
large projects with speed and efficiency.
Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent
on network access or a central server. Branching and merging are fast and easy to do.
What’s Git?
./
Rakefile
init.rb
lib
grant.rb
Working Directory
./
Rakefile
init.rb
lib
grant.rb
Working Directory
>git init
.git
./
Rakefile
init.rb
lib
grant.rb
Working Directory
>git init
What’s in here?.git
Objects
Git Objects
header
content
object_type [content size]\0content of the filecan be textcan be binarycan be whatever
Zlib::Deflate
Git Objects
1 Blob 2 Tree 3 Commit 4 Tag
header
content
object_type [content size]\0content of the filecan be textcan be binarycan be whatever
Zlib::Deflate
1 Blobs
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
>git add .>git commit -m “initial commit”
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
>git add .>git commit -m “initial commit”
blob : 644eda
blob : a22a24
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
>git add .>git commit -m “initial commit”
blob : 644eda
blob : a22a24
SHA-1 hashesof file content
Blob Content
Blob Content
>git cat-file -p 644eda
%w{ models }.each do |dir| path = File.join(File.dirname(__FILE__), 'lib', 'app', dir) $LOAD_PATH << path ActiveSupport::Dependencies.load_paths << path ActiveSupport::Dependencies.load_once_paths.delete(path)end
2 Trees
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
blob : 644eda
blob : a22a24
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
Tree Content
Tree Content
>git cat-file -p f2eb1e
100644 blob 21a30738954b6bb164731d822efafa6c89c7bce7! Rakefile100644 blob 644eda506db859e011ccbca5a06421ee76782ac7! init.rb040000 tree 523fa41bd27fa29a00afb0bef6a10fde75aef501! lib
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
3 Commits
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
commit : 3848fa
Commit Content
Commit Content
>git cat-file -p 3848fa
tree f2eb1e549e7e0d9cd5b7a580e63e9ce79d5a03aeauthor Jeff Kunkle <[email protected]> 1261341813 -0500committer Jeff Kunkle <[email protected]> 1261341813 -0500
initial commit
first commit
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
commit : 3848fa
./
Rakefile
init.rb
lib
grant.rb
Working Directory Git Directory
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
commit : 3848fa
Commit Content
tree ac451e549e7e0d9cd5b7a580e63e9ce79d5b45a1parent 3848fa7e91490a99b77590ff1385c4b3eebb3de3author Jeff Kunkle <[email protected]> 1261351813 -0500committer Jeff Kunkle <[email protected]> 1261351813 -0500
second commit
next commit
4 Tags
./
Rakefile
init.rb
lib
grant.rb
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
commit : 3848fa
./
Rakefile
init.rb
lib
grant.rb
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
commit : 3848fa
tag : e9eff3>git tag -a v1.0
Tag Content
Tag Content
>git cat-file -p v1.0
object 3848fa7e91490a99b77590ff1385c4b3eebb3de3type committag v1.0tagger Jeff Kunkle <[email protected]> Tue Dec 29 21:02:04 2009 -0500
version 1.0
./
Rakefile
init.rb
lib
grant.rb
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
commit : 3848fa
tag : e9eff3>git tag -a v1.0
./
Rakefile
init.rb
lib
grant.rb
blob : 21a307
blob : 644eda
blob : a22a24
tree : f2eb1e
tree : 523fa4
commit : 3848fa
tag : e9eff3>git tag -a v1.0
References
blob
tree
commit
tag
Basic Data Model
blob
tree
commit
tag
Basic Data Model
ImmutableGit Objects
blob
tree
commit
tag
Basic Data Model
ImmutableGit Objects
branch
blob
tree
commit
tag
Basic Data Model
ImmutableGit Objects
branch
blob
tree
commit
tag
Basic Data Model
ImmutableGit Objects
branch
HEAD
blob
tree
commit
tag
Basic Data Model
ImmutableGit Objects
branch
HEAD
MutableReferences
./
Rakefile
init.rb
lib
grant.rb
Working Directory
blobtree
commit
tagbranch
HEAD
blobtree
blob
blobtree
commit
tagbranch
HEAD
blobtree
blob
tree
commit
branch
HEAD
tree
blob
>git commit -a lib/grant.rb
>git commit -a Rakefile init.rb
blobtree
commit
tagbranch
HEAD
blobtree
blob
tree
commit
branch
HEAD
tree
blob
tree
commit
branch
HEAD
blob
blob
Branches
blob
tree
commit
branch
C1
branch
C
master
C
C
master
C
idea
>git checkout -b idea
C
master
C
C
idea
>git commit
C
master
C
C
idea
>git checkout master
C
master
C
C
idea
C
>git commit
C
master
C
C
idea
C
bug
>git checkout -b bug
C
master
C
C
idea
C
C
bug
>git commit
C
master
C
C
idea
C
C
bug
>git commit>git checkout master
C
master
C
C
idea
C
C
bug
>git commit>git merge bug
CC
C
idea
C
C
C
bug
master
>git commit>git merge bug>git commit
CC
C
idea
C
C
C
bug
master
>git commit>git merge bug>git commit>git branch -d bug
CC
C
idea
C
C
C
bug
master
>git commit>git merge bug>git commit>git branch -d bug>git checkout idea
CC
C C
C
idea
C
C
bug
master
>git commit>git merge bug>git commit>git branch -d bug>git checkout idea>git commit
CC
C C C
C
C
C
idea
bug
master
>git commit>git merge bug>git commit>git branch -d bug>git checkout idea>git commit>git commit
CC
C C C
C
C
C
idea
bug
master
>git commit>git merge bug>git commit>git branch -d bug>git checkout idea>git commit>git commit>git checkout master
CC
C C C
C
C
C
idea
bug
master
>git commit>git merge bug>git commit>git branch -d bug>git checkout idea>git commit>git commit>git checkout master>git merge idea
CC
C C C
CC
C
C
idea
bug
master
>git commit>git merge bug>git commit>git branch -d bug>git checkout idea>git commit>git commit>git checkout master>git merge idea>git commit
CC
C C C
CC
C
C
idea
bug
master
>git commit>git merge bug>git commit>git branch -d bug>git checkout idea>git commit>git commit>git checkout master>git merge idea>git commit>git branch -d idea
Recommendations
Starting new project?
Starting new project?
Use Git
Using SVN or CVS?
Using SVN or CVS?
Switch to Git
Using Team Studio?
Using Team Studio?
Maybe switch to Git
Using MKS?
Using MKS?
Switch to Gitor CVS, or Subversion, or anything else
References
Good Better Best*most diagrams in this presentation are based on Git internals