SlideShare une entreprise Scribd logo
1  sur  100
Fundamentals of Git
Usage and Internals
Jimmy Thrasher <jimmy@brownbirdlabs.com>
             @jimmythrasher
git
(n) - a contemptible person, often a fool
Philosophy
Basic Usage, Pass I
Initialize the repo
Initialize the repo

$ mkdir arithmetic; cd arithmetic
Initialize the repo

$ mkdir arithmetic; cd arithmetic

$ git init
Initialize the repo

$ mkdir arithmetic; cd arithmetic

$ git init
Initialized empty Git repository in <path>/arithmetic/.git/
Generate some code

   $ cat > arithmetic.rb
   def plus(a, b); a + b; end
   ^D
Stage the changes
Stage the changes
$ git add .
Stage the changes
$ git add .

$ git status
Stage the changes
$ git add .

$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
#
 new file: arithmetic.rb
#
Commit!
Commit!

$ git commit -m "First post"
Commit!

$ git commit -m "First post"
[master (root-commit) 0ca3306] First post
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 arithmetic.rb
20 GOTO 10
Basic Usage, Pass II
$ mkdir arithmetic; cd arithmetic

$ git init
Initialized empty Git repository in <path>/arithmetic/.git/
$ ls -l .git
$ ls -l .git
total 24
-rw-r--r--     1 jjthrash staff 23 Nov 6 21:05 HEAD
-rw-r--r--     1 jjthrash staff 111 Nov 6 21:05 config
-rw-r--r--     1 jjthrash staff 73 Nov 6 21:05 description
drwxr-xr-x     12 jjthrash staff 408 Nov 6 21:05 hooks
drwxr-xr-x      3 jjthrash staff 102 Nov 6 21:05 info
drwxr-xr-x      4 jjthrash staff 136 Nov 6 21:05 objects
drwxr-xr-x      4 jjthrash staff 136 Nov 6 21:05 refs
Generate some code

   $ cat > arithmetic.rb
   def plus(a, b); a + b; end
   ^D
$ git add .

$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
#
 new file: arithmetic.rb
#
The Object Store
$ cat arithmetic.rb | git hash-object --stdin
$ cat arithmetic.rb | git hash-object --stdin
171fe423f0146d107db5d5c94ba205d86549ff14
$ cat arithmetic.rb | git hash-object --stdin
171fe423f0146d107db5d5c94ba205d86549ff14

$ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14
$ cat arithmetic.rb | git hash-object --stdin
171fe423f0146d107db5d5c94ba205d86549ff14

$ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14
def plus(a, b); a + b; end
$ cat arithmetic.rb | git hash-object --stdin
171fe423f0146d107db5d5c94ba205d86549ff14

$ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14
def plus(a, b); a + b; end

$ find .git/objects -type f
$ cat arithmetic.rb | git hash-object --stdin
171fe423f0146d107db5d5c94ba205d86549ff14

$ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14
def plus(a, b); a + b; end

$ find .git/objects -type f
.git/objects/17/1fe423f0146d107db5d5c94ba205d86549ff14
$ cat .git/index
$ cat .git/index
arithmetic.rb?k>???#?m}?ϸk?S??`m?I??
$ git commit -m "First post"
[master (root-commit) 0ca3306] First post
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 arithmetic.rb
More Object Store
More Object Store




  ©Scott Chacon, Fig 9-1 “Git Internals—Git Objects”
More Object Store
More Object Store




  ©Scott Chacon, Fig 9-3 “Git Internals—Git Objects”
$ git rev-parse HEAD
$ git rev-parse HEAD
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
$ git rev-parse HEAD
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
$ git rev-parse HEAD
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
tree a9974d0f707a302dfd82370c357e87e1df813658
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463
-0500

First post
$ git rev-parse HEAD
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
tree a9974d0f707a302dfd82370c357e87e1df813658
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463
-0500

First post

$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
$ git rev-parse HEAD
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
tree a9974d0f707a302dfd82370c357e87e1df813658
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463
-0500

First post

$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14
arithmetic.rb
$ git rev-parse HEAD
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
tree a9974d0f707a302dfd82370c357e87e1df813658
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463
-0500

First post

$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14
arithmetic.rb

$ cat arithmetic.rb | git hash-object --stdin
$ git rev-parse HEAD
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
tree a9974d0f707a302dfd82370c357e87e1df813658
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463
-0500

First post

$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14
arithmetic.rb

$ cat arithmetic.rb | git hash-object --stdin
171fe423f0146d107db5d5c94ba205d86549ff14
$ find .git/objects -type f
$ find .git/objects -type f
.git/objects/0c/a330690c2d1471ca4aa4c18c8fe3f53883f7a3
.git/objects/17/1fe423f0146d107db5d5c94ba205d86549ff14
.git/objects/a9/974d0f707a302dfd82370c357e87e1df813658
Recap
Refs
$ find .git/refs -type f
$ find .git/refs -type f
.git/refs/heads/master
$ find .git/refs -type f
.git/refs/heads/master

$ cat .git/refs/heads/master
$ find .git/refs -type f
.git/refs/heads/master

$ cat .git/refs/heads/master
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
$ find .git/refs -type f
.git/refs/heads/master

$ cat .git/refs/heads/master
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git log
$ find .git/refs -type f
.git/refs/heads/master

$ cat .git/refs/heads/master
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git log
commit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master)
Author: Jimmy Thrasher <jimmy@jimmythrasher.com>
Date: Tue Nov 6 21:14:23 2012 -0500

  First post
$ find .git/refs -type f
.git/refs/heads/master

$ cat .git/refs/heads/master
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git log
commit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master)
Author: Jimmy Thrasher <jimmy@jimmythrasher.com>
Date: Tue Nov 6 21:14:23 2012 -0500

  First post

$ cat .git/HEAD
$ find .git/refs -type f
.git/refs/heads/master

$ cat .git/refs/heads/master
0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3

$ git log
commit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master)
Author: Jimmy Thrasher <jimmy@jimmythrasher.com>
Date: Tue Nov 6 21:14:23 2012 -0500

  First post

$ cat .git/HEAD
ref: refs/heads/master
Making History
Add another commit
Add another commit
$ cat >> arithmetic.rb
Add another commit
$ cat >> arithmetic.rb
def minus(a, b); a - b; end
Add another commit
$ cat >> arithmetic.rb
def minus(a, b); a - b; end

$ git add --patch
Add another commit
$ cat >> arithmetic.rb
def minus(a, b); a - b; end

$ git add --patch
diff --git a/arithmetic.rb b/arithmetic.rb
index 171fe42..5c66815 100644
--- a/arithmetic.rb
+++ b/arithmetic.rb
@@ -1 +1,2 @@
 def plus(a, b); a + b; end
+def minus(a, b); a - b; end
Stage this hunk [y,n,q,a,d,/,e,?]? y
Add another commit
$ cat >> arithmetic.rb
def minus(a, b); a - b; end

$ git add --patch
diff --git a/arithmetic.rb b/arithmetic.rb
index 171fe42..5c66815 100644
--- a/arithmetic.rb
+++ b/arithmetic.rb
@@ -1 +1,2 @@
 def plus(a, b); a + b; end
+def minus(a, b); a - b; end
Stage this hunk [y,n,q,a,d,/,e,?]? y

$ git commit -m "Double the featureset"
Add another commit
$ cat >> arithmetic.rb
def minus(a, b); a - b; end

$ git add --patch
diff --git a/arithmetic.rb b/arithmetic.rb
index 171fe42..5c66815 100644
--- a/arithmetic.rb
+++ b/arithmetic.rb
@@ -1 +1,2 @@
 def plus(a, b); a + b; end
+def minus(a, b); a - b; end
Stage this hunk [y,n,q,a,d,/,e,?]? y

$ git commit -m "Double the featureset"
[master d4655dd] Double the featureset
 1 files changed, 1 insertions(+), 0 deletions(-)
$ # the commit
$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
$ # the commit
$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
tree adaa5519b385d57417efc1667a9ab9d86473e578
parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222
-0500

Double the featureset
$ # the commit
$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
tree adaa5519b385d57417efc1667a9ab9d86473e578
parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222
-0500

Double the featureset

$ # the tree
$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578
$ # the commit
$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
tree adaa5519b385d57417efc1667a9ab9d86473e578
parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222
-0500

Double the featureset

$ # the tree
$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578
100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212

   arithmetic.rb
$ # the commit
$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
tree adaa5519b385d57417efc1667a9ab9d86473e578
parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222
-0500

Double the featureset

$ # the tree
$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578
100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212

   arithmetic.rb

$ # the old commit
$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
$ # the commit
$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
tree adaa5519b385d57417efc1667a9ab9d86473e578
parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222
-0500

Double the featureset

$ # the tree
$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578
100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212

   arithmetic.rb

$ # the old commit
$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
tree a9974d0f707a302dfd82370c357e87e1df813658
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463
-0500

First post
$ # the commit
$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
tree adaa5519b385d57417efc1667a9ab9d86473e578
parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222
-0500

Double the featureset

$ # the tree
$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578
100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212

   arithmetic.rb

$ # the old commit
$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
tree a9974d0f707a302dfd82370c357e87e1df813658
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463
-0500

First post

$ # the old tree
$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
$ # the commit
$ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
tree adaa5519b385d57417efc1667a9ab9d86473e578
parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222
-0500

Double the featureset

$ # the tree
$ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578
100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212

   arithmetic.rb

$ # the old commit
$ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
tree a9974d0f707a302dfd82370c357e87e1df813658
author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500
committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463
-0500

First post

$ # the old tree
$ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14
arithmetic.rb
Object Store




©Scott Chacon, Fig 9-3 “Git Internals—Git Objects”
Branching and Merging
$ git cat-file -p HEAD
$ git cat-file -p HEAD
tree 6436ce8f07792aec3ec132fc4abb59d2a827cba7
parent 772883c59078484dc8990ffbc509e249e22a6c84
parent ff3ab8a25f623d4ceb3ea189090879dc67693cb5
author Rafael Mendonça França <rafaelmfranca@gmail.com> 1352404208
-0800
committer Rafael Mendonça França <rafaelmfranca@gmail.com>
1352404208 -0800

Merge pull request #8115 from senny/
7842_handle_trailing_slash_with_engines

handle trailing slash with engines (test case for #7842)
master (HEAD)   C1
git checkout -b bug-142 master




        master       C1

bug-142 (HEAD)
#change code
  git commit -am “Fix problem with the widgets”




                       C2           bug-142 (HEAD)


master        C1
git checkout master




                                C2    bug-142


master (HEAD)          C1
# make more changes
         git commit -am “Moar changes!!1!”




master (HEAD)       C3          C2           bug-142


                         C1
git merge bug-142



master (HEAD)           C4




                   C3         C2    bug-142


                        C1
Rebasing
# got 2 branches




master (HEAD)        C3        C2   bug-142


                          C1
git checkout bug-142




master   C3         C2          bug-142 (HEAD)


              C1
git rebase master




                   C4        bug-142 (HEAD)


master   C3             C2



              C1
What didn’t I cover?
• Workflow recommendations
• Remotes, tags, “tree-ish”
• Working with other developers
• GitHub Pull Requests
• Handy tips and tricks
• etc
I Recommend


• Pro-Git, by Scott Chacon (free ebook)
• Everything git-related by @tpope
Thank You!
Q&A

Contenu connexe

Tendances

Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
akaptur
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
akaptur
 

Tendances (18)

Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
Flink meetup
Flink meetupFlink meetup
Flink meetup
 
Performance testing of microservices in Action
Performance testing of microservices in ActionPerformance testing of microservices in Action
Performance testing of microservices in Action
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
D1
D1D1
D1
 
Virtual Machine for Regular Expressions
Virtual Machine for Regular ExpressionsVirtual Machine for Regular Expressions
Virtual Machine for Regular Expressions
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Git basics 2
Git basics 2Git basics 2
Git basics 2
 
The Ring programming language version 1.5.1 book - Part 77 of 180
The Ring programming language version 1.5.1 book - Part 77 of 180The Ring programming language version 1.5.1 book - Part 77 of 180
The Ring programming language version 1.5.1 book - Part 77 of 180
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
 
FEAL - CSAW CTF 2014 Quals Crypto300
FEAL - CSAW CTF 2014 Quals Crypto300FEAL - CSAW CTF 2014 Quals Crypto300
FEAL - CSAW CTF 2014 Quals Crypto300
 
Diving into byte code optimization in python
Diving into byte code optimization in python Diving into byte code optimization in python
Diving into byte code optimization in python
 
test
testtest
test
 
Awk hints
Awk hintsAwk hints
Awk hints
 

En vedette

Git in gear: How to track changes, travel back in time, and code nicely with ...
Git in gear: How to track changes, travel back in time, and code nicely with ...Git in gear: How to track changes, travel back in time, and code nicely with ...
Git in gear: How to track changes, travel back in time, and code nicely with ...
fureigh
 

En vedette (10)

Git in gear: How to track changes, travel back in time, and code nicely with ...
Git in gear: How to track changes, travel back in time, and code nicely with ...Git in gear: How to track changes, travel back in time, and code nicely with ...
Git in gear: How to track changes, travel back in time, and code nicely with ...
 
GIT Fundamentals
GIT FundamentalsGIT Fundamentals
GIT Fundamentals
 
Git advanced
Git advancedGit advanced
Git advanced
 
Git Hogent
Git HogentGit Hogent
Git Hogent
 
A painless git workflow
A painless git workflowA painless git workflow
A painless git workflow
 
How to store large binary files in git repositories
How to store large binary files in git repositoriesHow to store large binary files in git repositories
How to store large binary files in git repositories
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
What is version control software and why do you need it?
What is version control software and why do you need it?What is version control software and why do you need it?
What is version control software and why do you need it?
 
Introduction to Version Control
Introduction to Version ControlIntroduction to Version Control
Introduction to Version Control
 
UX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and ArchivesUX, ethnography and possibilities: for Libraries, Museums and Archives
UX, ethnography and possibilities: for Libraries, Museums and Archives
 

Similaire à Git

GIT rozproszony system kontroli wersji
GIT rozproszony system kontroli wersjiGIT rozproszony system kontroli wersji
GIT rozproszony system kontroli wersji
3camp
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
Yasuhiro Asaka
 

Similaire à Git (20)

Git Aliases of the Gods!
Git Aliases of the Gods!Git Aliases of the Gods!
Git Aliases of the Gods!
 
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]Cool Git Tricks (That I Learn When Things Go Badly) [1/2]
Cool Git Tricks (That I Learn When Things Go Badly) [1/2]
 
Git Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a BossGit Magic: Versioning Files like a Boss
Git Magic: Versioning Files like a Boss
 
Git Tutorial Yang Yang
Git Tutorial Yang YangGit Tutorial Yang Yang
Git Tutorial Yang Yang
 
Get on with git
Get on with gitGet on with git
Get on with git
 
git internals
git internalsgit internals
git internals
 
Loading...git
Loading...gitLoading...git
Loading...git
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Get Good With Git
Get Good With GitGet Good With Git
Get Good With Git
 
GIT rozproszony system kontroli wersji
GIT rozproszony system kontroli wersjiGIT rozproszony system kontroli wersji
GIT rozproszony system kontroli wersji
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Essential git fu for tech writers
Essential git fu for tech writersEssential git fu for tech writers
Essential git fu for tech writers
 
Git - Get Ready To Use It
Git - Get Ready To Use ItGit - Get Ready To Use It
Git - Get Ready To Use It
 
Version Control and Git - GitHub Workshop
Version Control and Git - GitHub WorkshopVersion Control and Git - GitHub Workshop
Version Control and Git - GitHub Workshop
 
Git - a powerful version control tool
Git - a powerful version control toolGit - a powerful version control tool
Git - a powerful version control tool
 
もっとgit
もっとgitもっとgit
もっとgit
 
Gitosis on Mac OS X Server
Gitosis on Mac OS X ServerGitosis on Mac OS X Server
Gitosis on Mac OS X Server
 
simple Git
simple Git simple Git
simple Git
 
Git Basic
Git BasicGit Basic
Git Basic
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Git

  • 1. Fundamentals of Git Usage and Internals Jimmy Thrasher <jimmy@brownbirdlabs.com> @jimmythrasher
  • 2. git (n) - a contemptible person, often a fool
  • 6. Initialize the repo $ mkdir arithmetic; cd arithmetic
  • 7. Initialize the repo $ mkdir arithmetic; cd arithmetic $ git init
  • 8. Initialize the repo $ mkdir arithmetic; cd arithmetic $ git init Initialized empty Git repository in <path>/arithmetic/.git/
  • 9. Generate some code $ cat > arithmetic.rb def plus(a, b); a + b; end ^D
  • 11. Stage the changes $ git add .
  • 12. Stage the changes $ git add . $ git status
  • 13. Stage the changes $ git add . $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: arithmetic.rb #
  • 15. Commit! $ git commit -m "First post"
  • 16. Commit! $ git commit -m "First post" [master (root-commit) 0ca3306] First post 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 arithmetic.rb
  • 19. $ mkdir arithmetic; cd arithmetic $ git init Initialized empty Git repository in <path>/arithmetic/.git/
  • 20.
  • 21. $ ls -l .git
  • 22. $ ls -l .git total 24 -rw-r--r-- 1 jjthrash staff 23 Nov 6 21:05 HEAD -rw-r--r-- 1 jjthrash staff 111 Nov 6 21:05 config -rw-r--r-- 1 jjthrash staff 73 Nov 6 21:05 description drwxr-xr-x 12 jjthrash staff 408 Nov 6 21:05 hooks drwxr-xr-x 3 jjthrash staff 102 Nov 6 21:05 info drwxr-xr-x 4 jjthrash staff 136 Nov 6 21:05 objects drwxr-xr-x 4 jjthrash staff 136 Nov 6 21:05 refs
  • 23. Generate some code $ cat > arithmetic.rb def plus(a, b); a + b; end ^D
  • 24. $ git add . $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: arithmetic.rb #
  • 26.
  • 27. $ cat arithmetic.rb | git hash-object --stdin
  • 28. $ cat arithmetic.rb | git hash-object --stdin 171fe423f0146d107db5d5c94ba205d86549ff14
  • 29. $ cat arithmetic.rb | git hash-object --stdin 171fe423f0146d107db5d5c94ba205d86549ff14 $ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14
  • 30. $ cat arithmetic.rb | git hash-object --stdin 171fe423f0146d107db5d5c94ba205d86549ff14 $ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14 def plus(a, b); a + b; end
  • 31. $ cat arithmetic.rb | git hash-object --stdin 171fe423f0146d107db5d5c94ba205d86549ff14 $ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14 def plus(a, b); a + b; end $ find .git/objects -type f
  • 32. $ cat arithmetic.rb | git hash-object --stdin 171fe423f0146d107db5d5c94ba205d86549ff14 $ git cat-file -p 171fe423f0146d107db5d5c94ba205d86549ff14 def plus(a, b); a + b; end $ find .git/objects -type f .git/objects/17/1fe423f0146d107db5d5c94ba205d86549ff14
  • 33.
  • 36. $ git commit -m "First post" [master (root-commit) 0ca3306] First post 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 arithmetic.rb
  • 38. More Object Store ©Scott Chacon, Fig 9-1 “Git Internals—Git Objects”
  • 40. More Object Store ©Scott Chacon, Fig 9-3 “Git Internals—Git Objects”
  • 41.
  • 43. $ git rev-parse HEAD 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
  • 44. $ git rev-parse HEAD 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
  • 45. $ git rev-parse HEAD 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 tree a9974d0f707a302dfd82370c357e87e1df813658 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 First post
  • 46. $ git rev-parse HEAD 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 tree a9974d0f707a302dfd82370c357e87e1df813658 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 First post $ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
  • 47. $ git rev-parse HEAD 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 tree a9974d0f707a302dfd82370c357e87e1df813658 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 First post $ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658 100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14 arithmetic.rb
  • 48. $ git rev-parse HEAD 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 tree a9974d0f707a302dfd82370c357e87e1df813658 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 First post $ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658 100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14 arithmetic.rb $ cat arithmetic.rb | git hash-object --stdin
  • 49. $ git rev-parse HEAD 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 tree a9974d0f707a302dfd82370c357e87e1df813658 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 First post $ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658 100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14 arithmetic.rb $ cat arithmetic.rb | git hash-object --stdin 171fe423f0146d107db5d5c94ba205d86549ff14
  • 50.
  • 52. $ find .git/objects -type f .git/objects/0c/a330690c2d1471ca4aa4c18c8fe3f53883f7a3 .git/objects/17/1fe423f0146d107db5d5c94ba205d86549ff14 .git/objects/a9/974d0f707a302dfd82370c357e87e1df813658
  • 53. Recap
  • 54.
  • 55. Refs
  • 56.
  • 57. $ find .git/refs -type f
  • 58. $ find .git/refs -type f .git/refs/heads/master
  • 59. $ find .git/refs -type f .git/refs/heads/master $ cat .git/refs/heads/master
  • 60. $ find .git/refs -type f .git/refs/heads/master $ cat .git/refs/heads/master 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
  • 61. $ find .git/refs -type f .git/refs/heads/master $ cat .git/refs/heads/master 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git log
  • 62. $ find .git/refs -type f .git/refs/heads/master $ cat .git/refs/heads/master 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git log commit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master) Author: Jimmy Thrasher <jimmy@jimmythrasher.com> Date: Tue Nov 6 21:14:23 2012 -0500 First post
  • 63. $ find .git/refs -type f .git/refs/heads/master $ cat .git/refs/heads/master 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git log commit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master) Author: Jimmy Thrasher <jimmy@jimmythrasher.com> Date: Tue Nov 6 21:14:23 2012 -0500 First post $ cat .git/HEAD
  • 64. $ find .git/refs -type f .git/refs/heads/master $ cat .git/refs/heads/master 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 $ git log commit 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 (HEAD, master) Author: Jimmy Thrasher <jimmy@jimmythrasher.com> Date: Tue Nov 6 21:14:23 2012 -0500 First post $ cat .git/HEAD ref: refs/heads/master
  • 67. Add another commit $ cat >> arithmetic.rb
  • 68. Add another commit $ cat >> arithmetic.rb def minus(a, b); a - b; end
  • 69. Add another commit $ cat >> arithmetic.rb def minus(a, b); a - b; end $ git add --patch
  • 70. Add another commit $ cat >> arithmetic.rb def minus(a, b); a - b; end $ git add --patch diff --git a/arithmetic.rb b/arithmetic.rb index 171fe42..5c66815 100644 --- a/arithmetic.rb +++ b/arithmetic.rb @@ -1 +1,2 @@ def plus(a, b); a + b; end +def minus(a, b); a - b; end Stage this hunk [y,n,q,a,d,/,e,?]? y
  • 71. Add another commit $ cat >> arithmetic.rb def minus(a, b); a - b; end $ git add --patch diff --git a/arithmetic.rb b/arithmetic.rb index 171fe42..5c66815 100644 --- a/arithmetic.rb +++ b/arithmetic.rb @@ -1 +1,2 @@ def plus(a, b); a + b; end +def minus(a, b); a - b; end Stage this hunk [y,n,q,a,d,/,e,?]? y $ git commit -m "Double the featureset"
  • 72. Add another commit $ cat >> arithmetic.rb def minus(a, b); a - b; end $ git add --patch diff --git a/arithmetic.rb b/arithmetic.rb index 171fe42..5c66815 100644 --- a/arithmetic.rb +++ b/arithmetic.rb @@ -1 +1,2 @@ def plus(a, b); a + b; end +def minus(a, b); a - b; end Stage this hunk [y,n,q,a,d,/,e,?]? y $ git commit -m "Double the featureset" [master d4655dd] Double the featureset 1 files changed, 1 insertions(+), 0 deletions(-)
  • 73.
  • 74. $ # the commit $ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce
  • 75. $ # the commit $ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce tree adaa5519b385d57417efc1667a9ab9d86473e578 parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 Double the featureset
  • 76. $ # the commit $ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce tree adaa5519b385d57417efc1667a9ab9d86473e578 parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 Double the featureset $ # the tree $ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578
  • 77. $ # the commit $ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce tree adaa5519b385d57417efc1667a9ab9d86473e578 parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 Double the featureset $ # the tree $ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578 100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb
  • 78. $ # the commit $ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce tree adaa5519b385d57417efc1667a9ab9d86473e578 parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 Double the featureset $ # the tree $ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578 100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb $ # the old commit $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3
  • 79. $ # the commit $ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce tree adaa5519b385d57417efc1667a9ab9d86473e578 parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 Double the featureset $ # the tree $ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578 100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb $ # the old commit $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 tree a9974d0f707a302dfd82370c357e87e1df813658 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 First post
  • 80. $ # the commit $ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce tree adaa5519b385d57417efc1667a9ab9d86473e578 parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 Double the featureset $ # the tree $ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578 100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb $ # the old commit $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 tree a9974d0f707a302dfd82370c357e87e1df813658 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 First post $ # the old tree $ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658
  • 81. $ # the commit $ git cat-file -p d4655ddec0830408c8a9eb2e97ff882254aa72ce tree adaa5519b385d57417efc1667a9ab9d86473e578 parent 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352329222 -0500 Double the featureset $ # the tree $ git cat-file -p adaa5519b385d57417efc1667a9ab9d86473e578 100644 blob 5c66815e4bccb85068bc884ea7963fd45347c212 arithmetic.rb $ # the old commit $ git cat-file -p 0ca330690c2d1471ca4aa4c18c8fe3f53883f7a3 tree a9974d0f707a302dfd82370c357e87e1df813658 author Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 committer Jimmy Thrasher <jimmy@jimmythrasher.com> 1352254463 -0500 First post $ # the old tree $ git cat-file -p a9974d0f707a302dfd82370c357e87e1df813658 100644 blob 171fe423f0146d107db5d5c94ba205d86549ff14 arithmetic.rb
  • 82. Object Store ©Scott Chacon, Fig 9-3 “Git Internals—Git Objects”
  • 84.
  • 85. $ git cat-file -p HEAD
  • 86. $ git cat-file -p HEAD tree 6436ce8f07792aec3ec132fc4abb59d2a827cba7 parent 772883c59078484dc8990ffbc509e249e22a6c84 parent ff3ab8a25f623d4ceb3ea189090879dc67693cb5 author Rafael Mendonça França <rafaelmfranca@gmail.com> 1352404208 -0800 committer Rafael Mendonça França <rafaelmfranca@gmail.com> 1352404208 -0800 Merge pull request #8115 from senny/ 7842_handle_trailing_slash_with_engines handle trailing slash with engines (test case for #7842)
  • 88. git checkout -b bug-142 master master C1 bug-142 (HEAD)
  • 89. #change code git commit -am “Fix problem with the widgets” C2 bug-142 (HEAD) master C1
  • 90. git checkout master C2 bug-142 master (HEAD) C1
  • 91. # make more changes git commit -am “Moar changes!!1!” master (HEAD) C3 C2 bug-142 C1
  • 92. git merge bug-142 master (HEAD) C4 C3 C2 bug-142 C1
  • 94. # got 2 branches master (HEAD) C3 C2 bug-142 C1
  • 95. git checkout bug-142 master C3 C2 bug-142 (HEAD) C1
  • 96. git rebase master C4 bug-142 (HEAD) master C3 C2 C1
  • 97. What didn’t I cover? • Workflow recommendations • Remotes, tags, “tree-ish” • Working with other developers • GitHub Pull Requests • Handy tips and tricks • etc
  • 98. I Recommend • Pro-Git, by Scott Chacon (free ebook) • Everything git-related by @tpope
  • 100. Q&A

Notes de l'éditeur

  1. The audience: How many developers?\n\nQuestions: please interrupt with directly on-topic questions. Please save the anticipatory or unrelated questions to the end.\n
  2. git is a version control tool\n\nLinus Torvalds wrote it. Says he has a propensity for naming his projects after himself.\n\nDistributed: no latency commits, productivity when offline or server down, all repositories equal, create your own workflow.\n\nPowerful: lightweight branching, robust merging, rebase.\n\nFast: hard links when available, efficient lookups via FS\n\nBut it has abstractions bleeding from its pores. You really have to understand how it works to use it effectively. Hence, this presentation.\n
  3. Lean on your version control!\n- Avoid dead code, unnecessary/misleading comments, backup files\n- Make changes fearlessly\nUse your version control so that it can be leaned on\n- Meaningful commits and commit messages\n- Keep commits small and distinct\n- Avoid unnecessary formatting changes\nReasoning about the code base\n- Your version control needs to have a coherent history\n
  4. \n
  5. \n
  6. \n
  7. \n
  8. Make changes to the working copy\n
  9. Make changes to the index\n
  10. Make changes to the index\n
  11. Make changes to the index\n
  12. Make changes to the index\n
  13. Make changes to the index\n
  14. Make changes to the index\n
  15. Make changes to the index\n
  16. Make changes to the index\n
  17. Make changes to the index\n
  18. Make changes to the index\n
  19. Make changes to the index\n
  20. Make changes to the object store\n\nThese are the three areas you work with: the working copy, the staging area or index, the object store.\n
  21. Make changes to the object store\n\nThese are the three areas you work with: the working copy, the staging area or index, the object store.\n
  22. Make changes to the object store\n\nThese are the three areas you work with: the working copy, the staging area or index, the object store.\n
  23. Make changes to the object store\n\nThese are the three areas you work with: the working copy, the staging area or index, the object store.\n
  24. Making changes, staging them, and committing is the majority of what you do in git.\n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. Make changes to the working copy\n
  37. \n
  38. Key/Value database\nKey is the SHA1 hash of the Value\n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. Three main types of objects in the object store. The two depicted here are blobs and trees.\nA blob represents files in the filesystem.\nA tree represents directories in the filesystem.\n
  49. Three main types of objects in the object store. The two depicted here are blobs and trees.\nA blob represents files in the filesystem.\nA tree represents directories in the filesystem.\n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. Where are we now? We have learned:\n- the three main types of objects in the object store\n- commits are snapshots of the working copy\n- commit history is a directed acyclic graph of commits\n- commits are documents that point to trees and other commits\n- trees are documents that point to blobs and other trees\n- blobs are the end of the line\n\nWhat are we missing?\n(cat picture)\n
  68. \n
  69. I referred to HEAD earlier. What&amp;#x2019;s that?\nIt&amp;#x2019;s called a ref. Refs point to commits, sometimes directly, sometimes indirectly. HEAD is a ref to the branch you&amp;#x2019;re currently on.\n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. git add --patch is a great way to stage only the changes you want.\n
  83. git add --patch is a great way to stage only the changes you want.\n
  84. git add --patch is a great way to stage only the changes you want.\n
  85. git add --patch is a great way to stage only the changes you want.\n
  86. git add --patch is a great way to stage only the changes you want.\n
  87. git add --patch is a great way to stage only the changes you want.\n
  88. git add --patch is a great way to stage only the changes you want.\n
  89. git add --patch is a great way to stage only the changes you want.\n
  90. git add --patch is a great way to stage only the changes you want.\n
  91. git add --patch is a great way to stage only the changes you want.\n
  92. git add --patch is a great way to stage only the changes you want.\n
  93. git add --patch is a great way to stage only the changes you want.\n
  94. git add --patch is a great way to stage only the changes you want.\n
  95. git add --patch is a great way to stage only the changes you want.\n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. A branch is just a different HEAD reference. It may or may not point to the same commit as another branch.\nMerging means creating a commit with 2 parent commits.\n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. Say you have a commit in your master branch\n
  126. Create what&amp;#x2019;s called a topic branch.\nbug-142 is now your current branch.\n
  127. Fix your code and check in your changes.\n
  128. Go back to master while you wait for the bug-142 branch to be verified, merged, whatever.\n
  129. Make a small change and commit.\n
  130. Merge bug-142 into master\n\nNotice bug-142 still points to its old commit. Merging typically doesn&amp;#x2019;t affect anything but the HEAD.\n
  131. Where merging is joining two or more nodes into one node by creating a new node,\nrebasing is cutting a portion of the graph off and reparenting it.\nHow does this work? &lt;replay patches&gt;\n
  132. Let&amp;#x2019;s say we have the two branches from before, but this time, I want my bug-142 branch to be rebased off of master. This could be to incorporate changes master has, or whatever.\n
  133. Check out bug-142 again\n
  134. Do the rebase!\n\nIt backs C2 out and pushes it onto a stack of patches\nThen it moves to C3.\nThen it replays the patch.\n\nThis creates new commits. Why? New trees, new commit timestamps, etc, all lead to new SHA1 hashes.\n\nNotice the dangling C2.\n\nThis is an important principle. VERY RARELY does stuff get expunged from your object store. It&amp;#x2019;s typically add-only.\n
  135. \n
  136. \n
  137. \n
  138. Just to get the polarizing irrelevant stuff:\nVim, not emacs. Spaces, not tabs. Ruby, not Python. Black licorice (red licorice isn&amp;#x2019;t fit to bear the name).\nI won&amp;#x2019;t tell you my distro of choice because of where we are. ;)\n