Git Workshop - Trunk Based Development
Git Workshop - Trunk Based Development
4
Connect to Linux shell
username: git01, git02, …, git11
host: 192.168.1.32
THE ANATOMY OF
A GIT COMMIT
1. 40 character revision
identifiers that are actually
$ echo -n "thoughtram" | openssl sha1
SHA-1 hashes
2. Hashes over hashes
a9eb85ea214a6cfa6882f4be041d5cce7
3. Tree object bee3e45
4. Commit object
6
THE ANATOMY OF
A GIT COMMIT sha1(
meta data
1. 40 character revision
identifiers that are actually commit message
SHA-1 hashes commiter
2. Hashes over hashes
3. Tree object commit date
4. Commit object author
authoring date
Hash-Of-Entire-Working-Directory
)
7
THE ANATOMY OF
A GIT COMMIT
There are four types of objects in Git’s
1. 40 character revision
identifiers that are actually internal storage.
SHA-1 hashes
2. Hashes over hashes
3. Tree object 1) commit objects,
4. Commit object 2) annotated tag objects,
3) blobs, and
4) tree objects
8
THE ANATOMY OF Let’s assume the following project
A GIT COMMIT structure and then examine how it is
represented with the corresponding
1. 40 character revision tree object.
identifiers that are actually
SHA-1 hashes
2. Hashes over hashes .
3. Tree object |-- .git
4. Commit object
|-- assets
| |-- logo.png
| |-- app.css
|-- app.js
9
10
THE ANATOMY OF sha1(
commit message
A GIT COMMIT => "initial commit"
commiter
1. 40 character revision => Christoph Burgdorf <[email protected]>
identifiers that are actually
SHA-1 hashes commit date
=> Sat Nov 8 10:56:57 2014 +0100
2. Hashes over hashes
3. Tree object Author
4. Commit object => Christoph Burgdorf <[email protected]>
author date
=> Sat Nov 8 10:56:57 2014 +0100
Tree
=> 9c435a86e664be00db0d973e981425e4a3ef3f8d
)
11
Source: A Tale of Three Trees (by Scott Chacon)
12
sha1(
commit message
THE ANATOMY OF => "initial commit"
Tree
=> 9c435a86e664be00db0d973e981425e4a3ef3f8d
Parents
=> [0d973e9c4353ef3f8ddb98a86e664be001425e4a]
) 13
Source: A Tale of Three Trees (by Scott Chacon)
14
Git = Blockchain
Mind = Blown
https://medium.com/@shemnon/is-a-git-repository-a-block
chain-35cb1cd2c491
15
16
UNDERSTANDING
BRANCHES IN GIT
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
17
UNDERSTANDING
BRANCHES IN GIT $ git branch feature
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
18
UNDERSTANDING
BRANCHES IN GIT
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
19
UNDERSTANDING
BRANCHES IN GIT $ git checkout feature
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
20
$ vim file.txt
UNDERSTANDING $ git add file.txt
BRANCHES IN GIT $ git commit -m “yay, that’s fun”
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
21
$ git checkout master
UNDERSTANDING
BRANCHES IN GIT
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
22
$ vim anotherFile.txt
UNDERSTANDING $ git add anotherFile.txt
BRANCHES IN GIT $ git commit -m "yay, more fun!"
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
23
UNDERSTANDING
BRANCHES IN GIT $ git merge --no-ff feature
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
24
sha1(
commit message
UNDERSTANDING => "Merge branch ‘feature’"
Parents
=> [3aa2ff, c57e22]
) 25
What if we model it as
if it was a relational
database?
Commit
UNDERSTANDING id what when who why parent1 parent2
BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null
1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id
1 HEAD 2 null
27
Commit
UNDERSTANDING id what when who why parent1 parent2
BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null
1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id
1 HEAD 2 null
BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null
1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id
1 HEAD 2 null
BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null
1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id
1 HEAD 3 null
BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null
1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer c57e22 6a16j1736j Sat Nov 8 Christoph fourth a5c3eb null
1 HEAD 3 null
BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null
1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer c57e22 6a16j1736j Sat Nov 8 Christoph fourth a5c3eb null
1 HEAD 2 null
BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null
1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer c57e22 6a16j1736j Sat Nov 8 Christoph fourth a5c3eb null
4. Checkout “feature” branch 3aa2ff 1jh351ha13 Sat Nov 8 Christoph fifth a5c3eb null
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id
1 HEAD 2 null
BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null
1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer c57e22 6a16j1736j Sat Nov 8 Christoph fourth a5c3eb null
4. Checkout “feature” branch 3aa2ff 1jh351ha13 Sat Nov 8 Christoph fifth a5c3eb null
5. Add new file
6. Checkout “master” branch a35e4v 66ga62314a Sat Nov 8 Christoph Merge feature 3aa2ff c57e22
1 HEAD 2 null
2. https://blog.thoughtram.io/git/rebase-book/20
References
15/02/10/understanding-branches-in-git.html
3. https://github.com/thoughtram/rebase-book/
blob/master/manuscript/branching-in-git.md
4. https://speakerdeck.com/schacon/a-tale-of-th
ree-trees
5. https://speakerdeck.com/jirichara/trunk-base
d-development
6. https://trunkbaseddevelopment.com
7. https://unsplash.com/photos/ywRNdDfvMWs
Thanks!
Leonardo Situmorang
[email protected]
@ldoreno