Git is a version control system that stores changes to files in a special database. It tracks files and folders and allows users to commit snapshots of a project over time. The document discusses how Git initializes a repository, stages and commits changes, stores file snapshots in its object database, and tracks changes through commit objects, tree objects, and references. It also shows how to add another commit to change a file and extend the project history.
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
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
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)
97. What didn’t I cover?
• Workflow recommendations
• Remotes, tags, “tree-ish”
• Working with other developers
• GitHub Pull Requests
• Handy tips and tricks
• etc
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
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
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
\n
\n
\n
\n
Make changes to the working copy\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
Make changes to the index\n
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
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
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
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
Making changes, staging them, and committing is the majority of what you do in git.\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Make changes to the working copy\n
\n
Key/Value database\nKey is the SHA1 hash of the Value\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
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
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
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
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
\n
I referred to HEAD earlier. What&#x2019;s that?\nIt&#x2019;s called a ref. Refs point to commits, sometimes directly, sometimes indirectly. HEAD is a ref to the branch you&#x2019;re currently on.\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
git add --patch is a great way to stage only the changes you want.\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
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
\n
\n
\n
\n
\n
\n
\n
\n
Say you have a commit in your master branch\n
Create what&#x2019;s called a topic branch.\nbug-142 is now your current branch.\n
Fix your code and check in your changes.\n
Go back to master while you wait for the bug-142 branch to be verified, merged, whatever.\n
Make a small change and commit.\n
Merge bug-142 into master\n\nNotice bug-142 still points to its old commit. Merging typically doesn&#x2019;t affect anything but the HEAD.\n
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? <replay patches>\n
Let&#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
Check out bug-142 again\n
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&#x2019;s typically add-only.\n
\n
\n
\n
Just to get the polarizing irrelevant stuff:\nVim, not emacs. Spaces, not tabs. Ruby, not Python. Black licorice (red licorice isn&#x2019;t fit to bear the name).\nI won&#x2019;t tell you my distro of choice because of where we are. ;)\n