18. Un peu
d’histoire…
2002
1991
Manual tarballs,
patches, mails
« Much superior source
control management
system than CVS is »
2005
Bitkeeper
Controversé car commercial
Does the job right!
Conditions:
• No reverse-engineering
• No development of competing
solution
19. Un peu
d’histoire…
2002
1991
Manual tarballs,
patches, mails
« Much superior source
control management
system than CVS is »
Aujourd’hui
2005
Bitkeeper
Controversé car commercial
Does the job right!
Conditions:
• No reverse-engineering
• No development of competing
solution
Git
• Linus Torvals
• Junio C Hamano
29. Git is Distributed
No a priori structure
Dan
The Boss
Charlie
Alice
Bob
But Git ≠ Anarchy
30. Git is Distributed
A very common practice:
Sharing via user-owned repos
Dan
Public
Dan
The Boss
Charlie
Charlie
Public
Alice
Public
Alice
Bob
Bob
Public
31. Git is Distributed
A very common practice:
Sharing via user-owned repos
RD/WR
Dan
Public
Dan
The Boss
Charlie
Charlie
Public
Bob
Bob
Public
READ
ONLY
Alice
Public
Alice
32. Git is Distributed
A very common practice:
Sharing via user-owned repos
Dan
Public
Charlie
Public
Where to host these?
Alice
Public
Bob
Public
33. Git is Distributed
Shared Repositories
Dan
Public
Charlie
Public
Alice
Public
Bob
Public
« In-House », entreprise-local
• Pure Git
• Assisted: Gitosis/Gitlite
• Web-based:
34. Git is Distributed
Shared Repositories
Dan
Public
Charlie
Public
Alice
Public
Bob
Public
« In-House », entreprise-local
• Pure Git
• Assisted: Gitosis/Gitlite
• Web-based:
Hosted
• Private/Public (often, private = €)
46. Git is Fast
1. Because it’s distributed: No network
overhead for daily operations:
– Commit changes
– Compare revisions
– View the history
– Create a branch
– Switch branches
– Merge branches
– … and many more
Alice
Alice
Public
47. Git is Fast
1. Because it’s distributed: No network
overhead for daily operations:
– Commit changes
– Compare revisions
– View the history
– Create a branch
– Switch branches
– Merge branches
– … and many more
Alice
100% local
Alice
Public
48. Git is Fast
1. Because it’s distributed: No network
overhead for daily operations:
– Commit changes
– Compare revisions
– View the history
– Create a branch
– Switch branches
– Merge branches
– … and many more
Alice
100% local
local = fast ?
Alice
Public
49. Git is Fast
2. Because it uses DAG-Storage over a
unique Content-Addressable File
System
56. Version 1
Delta
Storage
Version 2
A
Δ A1
Version 4
Δ B1
Δ C1
Version 1
Version 2
A
A1
B
B
C
C1
Version 5
Δ A2
B
C
DAG
Storage
Version 3
Δ C2
Δ B2
Δ C3
57. Version 1
Delta
Storage
Version 2
A
Δ A1
Version 3
Version 5
Δ A2
B
Δ B1
C
Δ C1
Δ C2
Version 1
DAG
Storage
Version 4
Version 2
Version 3
A
A1
A1
B
B
B
C
C1
C2
Δ B2
Δ C3
58. Version 1
Delta
Storage
Version 2
A
Δ A1
Version 3
Version 4
Δ A2
B
Δ B1
C
Δ C1
Δ C2
Version 1
DAG
Storage
Version 5
Version 2
Version 3
Version 4
A
A1
A1
A2
B
B
B
B1
C
C1
C2
C2
Δ B2
Δ C3
59. Version 1
Delta
Storage
Version 2
A
Δ A1
Version 3
Version 4
Version 5
Δ A2
B
Δ B1
Δ B2
C
Δ C2
Version 1
DAG
Storage
Δ C1
Version 2
Version 3
Version 4
Version 5
A
A1
A1
A2
A2
B
B
B
B1
B2
C
C1
C2
C2
C3
Δ C3
70. Git Object Database
blob
tree
Blob = Content
High reuse (like all Git objects)
commit
tag
project/
├── .git
└── README
blob 60
ce/01362
hello
Git Object Database
71. Git Object Database
blob
tree
commit
tag
$ cp README file2.txt (copy REAME)
$ echo test > file3.txt (create file3.txt)
$ git add file2.txt file3.txt
contents of
file3.txt
$ find .git/objects –type f
.git/objects/9d/aeafb9864cf43055ae93beb0afd6c7d144bfa4
.git/objects/ce/013625030ba8dba906f756967f9e9ca394464a
contents
of README
project/
├── .git
├── file2.txt
├── file3.txt
└── README
=
contents of
file2.txt
blob 50
9d/aeafb
test
blob 60
ce/01362
hello
Git Object Database
72. Git Object Database
blob
New Contents New Blobs
Files in a content-addressable FS
tree
commit
tag
Other Git Objects behave
exactly the same way
73. Git Object Database
blob
tree
commit
tag
$ git commit –m "Mon premier commit"
$ git log
commit 8e8eb678d9512d421e590350e3100dc51ead6b7a
Author: Sébastien Dawans
<sebastien.dawans@cetic.be>
Date:
Sun Apr 14 22:26:29 2013 +0200
Mon premier commit
74. Git Object Database
blob
tree
commit
tag
$ git commit –m "Mon premier commit"
$ git log
commit 8e8eb678d9512d421e590350e3100dc51ead6b7a
Author: Sébastien Dawans
<sebastien.dawans@cetic.be>
Date:
Sun Apr 14 22:26:29 2013 +0200
Mon premier commit
$ tree .git/objects/
.git/objects/
├── 8e
│
└── 8eb678d9512d421e590350e3100dc51ead6b7a
├── 91
│
└── dc8d579f123918f3ac43af1e9377a97128763b
├── 9d
│
└── aeafb9864cf43055ae93beb0afd6c7d144bfa4
├── ce
│
└── 013625030ba8dba906f756967f9e9ca394464a
87. This makes Git Fast
• Restore an arbitrary version
– Git: checkout a hash = O(1)
– SVN: diffs between n last commits = O(n)
•
•
•
•
Compare 2 revisions
Reset
Search through history
And many more…
88. Some Benchmarking
Operation
Git
SVN
Add, commit and push 113 modified files (2164+, 2259-)
0.64
2.60
4x
Add, commit and push 1000 1k images
1.53
24.70
16x
Diff 187 changed files (1664+, 4859-) against last commit
0.25
1.09
4x
Diff against 4 commits back (269 changed/3609+,6898-)
0.25
3.99
16x
Diff two tags against each other
1.17
83.57
71x
Log of the last 50 commits (19k of output)
0.01
0.38
31x
Log of all commits (26,056 commits - 9.4M of output)
0.52
169.20 325x
Log of the history of a single file
0.60
82.84
138x
Pull of Commit A scenario (113 files changed, 2164+, 2259-)
0.90
2.82
3x
Line annotation of a single file (array.c)
1.91
3.04
1x
http://git-scm.com/about/small-and-fast
90. Git is Reliable
1. Because it’s Distributed
– Single dev with a remote? 2 copies (local,
remote)
– .git/ has it all
2. Checksums (SHA-1) for all objects Git uses
– Detects data corruption
– Guarantees Authenticity
100. origin
Working
Directory
Staging
Area
Local
Repo
$ git status
# On branch crazy-idea
nothing to commit (working directory clean)
... hack your crazy idea
add new files, modify others ...
HEAD
master
8b5b2bd
704309c
crazy-idea
424a7b2
origin/master
origin/HEAD
Remote
Repo
101. origin
Working
Directory
Staging
Area
Local
Repo
Remote
Repo
$ git status
# On branch crazy-idea
# Changes not staged for commit:
#
(use "git add <file>..." to update what will be committed)
#
(use "git checkout -- <file>..." to discard changes in working directory)
#
#
modified:
core/net/rpl/rpl.c
#
modified:
core/net/tcpip.c
#
# Untracked files:
#
(use "git add <file>..." to include in what will be committed)
#
#
core/net/newfile.c
no changes added to commit (use "git add" and/or "git commit -a")
HEAD
master
8b5b2bd
704309c
crazy-idea
424a7b2
origin/master
origin/HEAD
102. origin
Working
Directory
Staging
Area
Local
Repo
Remote
Repo
$ git status
# On branch crazy-idea
# Changes not staged for commit:
#
(use "git add <file>..." to update what will be committed)
#
(use "git checkout -- <file>..." to discard changes in working directory)
#
Modification
#
modified:
core/net/rpl/rpl.c
of tracked content
#
modified:
core/net/tcpip.c
#
# Untracked files:
#
(use "git add <file>..." to include in what will be committed)
#
#
core/net/newfile.c
no changes added to commit (use "git add" and/or "git commit -a")
HEAD
master
8b5b2bd
704309c
crazy-idea
424a7b2
origin/master
origin/HEAD
103. origin
Working
Directory
Staging
Area
Local
Repo
Remote
Repo
$ git status
# On branch crazy-idea
# Changes not staged for commit:
#
(use "git add <file>..." to update what will be committed)
#
(use "git checkout -- <file>..." to discard changes in working directory)
#
Modification
#
modified:
core/net/rpl/rpl.c
of tracked content
#
modified:
core/net/tcpip.c
#
# Untracked files:
#
(use "git add <file>..." to include in what will be committed)
#
#
core/net/newfile.c
New, untracked content
no changes added to commit (use "git add" and/or "git commit -a")
HEAD
master
8b5b2bd
704309c
crazy-idea
424a7b2
origin/master
origin/HEAD
105. origin
Working
Directory
Staging
Area
Local
Repo
Remote
Repo
$ git status
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
# On branch crazy-idea
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified:
core/net/rpl/rpl.c
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified:
core/net/tcpip.c
Untracked files:
(use "git add <file>..." to include in what will be committed)
HEAD
core/net/newfile.c
master
8b5b2bd
704309c
crazy-idea
424a7b2
origin/master
origin/HEAD
106. origin
Working
Directory
Staging
Area
Local
Repo
Remote
Repo
$ git status
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
# On branch crazy-idea
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified:
core/net/rpl/rpl.c
Content of the
next commit
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified:
core/net/tcpip.c
Untracked files:
(use "git add <file>..." to include in what will be committed)
HEAD
core/net/newfile.c
master
8b5b2bd
704309c
crazy-idea
424a7b2
origin/master
origin/HEAD
108. origin
Working
Directory
Staging
Area
Local
Repo
Remote
Repo
$ git status
# On branch crazy-idea
# Changes not staged for commit:
#
(use "git add <file>..." to update what will be committed)
#
(use "git checkout -- <file>..." to discard changes in working directory)
#
#
modified:
core/net/tcpip.c
#
# Untracked files:
#
(use "git add <file>..." to include in what will be committed)
#
#
core/net/newfile.c
no changes added to commit (use "git add" and/or "git commit -a")
HEAD
4c5bae0
master
8b5b2bd
704309c
424a7b2
origin/master
origin/HEAD
crazy-idea
113. Merges are done LOCALLY!
“Git push failed, To prevent from
losing history, non-fast forward
updates were rejected”
Not an error, but common-sense
Files are rarely decorrelated
122. Now our contribution is public
Ready to be merged
8b5b2bd
704309c
424a7b2
4c5bae0
HEAD
crazy-idea
master
2cac7e2
origin/master
origin/HEAD
HEAD
crazy-idea
8b5b2bd
704309c
424a7b2
origin/master
origin/HEAD
4c5bae0
master
2cac7e2
cetic/master
123. Now our contribution is public
Ready to be merged
8b5b2bd
704309c
424a7b2
4c5bae0
HEAD
crazy-idea
master
2cac7e2
origin/master
origin/HEAD
1. Fetch+merge (done by owners of origin)
2. Pull-Request (involves both parties)
crazy-idea
8b5b2bd
704309c
424a7b2
4c5bae0
HEAD
master
2cac7e2
cetic/master
origin/master
origin/HEAD
142. Squashing commits
12fff12
« Code style »
7434b12
« ISSUUEE #3255 »
ea3222c
« Resolves issue #2342,
More text describing the fix »
abcdef0
squashed
143. Squashing commits
12fff12
« Code style »
Child commits affected!
7434b12
« ISSUUEE #3255 »
ea3222c
« Resolves issue #2342,
More text describing the fix »
abcdef0
squashed
144. Squashing commits
12fff12
« Code style »
7434b12
« ISSUUEE #3255 »
8b5b2bd
« Resolves issue #2342,
More text describing the fix »
abcdef0
Amend the commit message
145. Squashing commits
1212121
« Code style »
9876543
« Resolves issue #3255 »
8b5b2bd
« Resolves issue #2342,
More text describing the fix »
abcdef0
Clean History,
can be merged
146. 1212121
« Code style »
9876543
« Resolves issue #3255 »
8b5b2bd
« Resolves issue #2342,
More text describing the fix »
abcdef0
147. Cherry-Picking
“Given one or more existing commits, apply the change each
one introduces, recording a new commit for each.”
D
I
C
H
B
G
A
F
abcdef0
M
L
git cherry-pick B C
148. Cherry-Picking
“Given one or more existing commits, apply the change each
one introduces, recording a new commit for each.”
D
I
B’
C
H
B
G
A
F
abcdef0
M
L
git cherry-pick B C
149. Cherry-Picking
“Given one or more existing commits, apply the change each
one introduces, recording a new commit for each.”
C’
D
I
B’
C
H
B
G
A
F
abcdef0
M
L
git cherry-pick B C
150. Don’t miss out on…
•
•
•
•
git
git
git
git
add –p
blame
diff
reset (soft/normal/hard)
151. Working together with Git
• « Workflow » ?
– How to structure a repository
• Branches and their interactions
• How the project moves forward
– Organizing people
• Who accesses what
• How are contributions merged? Where? By who?
• Responsibilities
152. Working together with Git
• « Workflow » ?
–How to structure a repository
• Branches and their interactions
• How the project moves forward
– Organizing people
• Who accesses what
• How are contributions merged? Where? By who?
• Responsibilities
160. Working together with Git
• « Workflow » ?
– How to structure a repository
• Branches and their interactions
• How the project moves forward
– Organizing people
• Who accesses what
• How are contributions merged? Where? By
who?
• Responsibilities