Git Knowledge Night:
A Bottom up Deep Dive

fhLUG

Linux User Group FH Hagenberg

* c736a04 (HEAD -> master, origin/pr) Awesomify README
*   68c29bb (tag: 1.0.0, origin/master) Merge branch 'feature'
|\
| * 68a9000 (feature) commit on feature branch
* | 6266d66 (tag: 0.0.1) Add contact information
|/
* 189dbe5 moving stuff
* eb4bda6 initial

Init

$ git init
$ cat .git/config
.git/objects/
.git/hooks/
.git/refs/
$ cat .git/HEAD
.git/branches/
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
ref: refs/heads/master

.git/refs/heads/master does not exist yet

Add

$ printf 'A' > a
$ git add a
$ xxd .git/objects/8c/7e5a667f1b771847fe88c01c3de34413a1b220
00000010: 7801 4bca c94f 5230 6470 0400 0be4 0232	x.K..OR0dp.....2

Add

$ pigz -d - < .git/objects/8c/7e5a667f1b771847fe88c01c3de34413a1b220 | xxd
00000000: 626c 6f62 2031 0041	blob1A
$ printf 'blob 1\0A' | sha1sum
8c7e5a667f1b771847fe88c01c3de34413a1b220
$ printf 'blob 0\0' | sha1sum
e69de29bb2d1d6434b8b29ae775ad8c2e48c5391

Initial commit

$ git commit -m 'initial'
.git/objects/eb/4bda62471a803e59fe0ac88a50eb6ce59823d7
00000000: 7801 ad8e 4b0e c230 0c05 59e7 14de 57a0  x...K..0..Y...W.
00000010: 389f 4225 8458 2036 9cc2 71dd 6235 69a4  8.B%.X 6..q.b5i.
00000020: 2adc 9f8a 33b0 7cb3 9879 5c4b d106 cef6  *...3.|..y\K....
00000030: 87b6 89c0 3906 f489 26e6 1eb9 f7c9 a534  ....9...&......4
00000040: 053a 731c 030b 8a4d d3e8 d905 6fe8 d3de  .:s....M....o...
00000050: 7583 07ad 2a19 5eab b696 8fcf 8dd6 05ae  u...*.^.........
00000060: cb6f 5d86 6ed6 769f 6b9d b314 d27c e25a  .o].n.v.k....|.Z
00000070: 6e80 31a2 c521 4607 9d45 6bcd 4ef7 0b4d  n.1..!F..Ek.N..M
00000080: fe22 33ba b795 b2f9 0291 f344 b8         ."3........D.
  • zlib header
  • Compressed data
  • Adler-32 checksum

Initial commit

.git/objects/eb/4bda62471a803e59fe0ac88a50eb6ce59823d7 (zlib)
00000000: 636f 6d6d 6974 2032 3036 0074 7265 6520  commit 206.tree 
00000010: 3735 3431 3362 6166 6363 3631 6336 3362  75413bafcc61c63b
00000020: 3262 6266 3461 3763 3564 3463 6531 6530  2bbf4a7c5d4ce1e0
00000030: 6266 6433 6332 3433 0a61 7574 686f 7220  bfd3c243.author 
00000040: 4461 6e69 656c 204b 6e69 7474 6c2d 4672  Daniel Knittl-Fr
00000050: 616e 6b20 3c6b 6e69 7474 6c38 392b 6769  ank <knittl89+gi
00000060: 7440 676f 6f67 6c65 6d61 696c 2e63 6f6d  t@googlemail.com
00000070: 3e20 3135 3531 3031 3935 3532 202b 3031  > 1551019552 +01
00000080: 3030 0a63 6f6d 6d69 7474 6572 2044 616e  00.committer Dan
00000090: 6965 6c20 4b6e 6974 746c 2d46 7261 6e6b  iel Knittl-Frank
000000a0: 203c 6b6e 6974 746c 3839 2b67 6974 4067   <knittl89+git@g
000000b0: 6f6f 676c 656d 6169 6c2e 636f 6d3e 2031  ooglemail.com> 1
000000c0: 3535 3130 3139 3535 3220 2b30 3130 300a  551019552 +0100.
000000d0: 0a69 6e69 7469 616c 0a                   .initial.
commit206tree 75413bafcc61c63b2bbf4a7c5d4ce1e0bfd3c243↲
author Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551019552 +0100↲
committer Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551019552 +0100↲

initial↲

Initial commit ^{tree}

$ git rev-parse eb4bda62471a803e59fe0ac88a50eb6ce59823d7^{tree}
.git/objects/75/413bafcc61c63b2bbf4a7c5d4ce1e0bfd3c243 (zlib)
00000000: 7472 6565 2032 3900 3130 3036 3434 2061  tree29.100644a
00000010: 008c 7e5a 667f 1b77 1847 fe88 c01c 3de3  ..~Zf..w.G....=.
00000020: 4413 a1b2 20                             D... 

Next commit

$ mkdir subdir; mv a subdir/b; git commit -m 'moving stuff' 
.git/objects/18/9dbe5ef6a95867109b18cd44a6eb593120b9b5 (zlib)
00000000: 636f 6d6d 6974 2032 3539 0074 7265 6520  commit 259.tree 
00000010: 3161 6665 6465 6336 6563 3766 6436 3331  1afedec6ec7fd631
00000020: 6438 3262 3732 3337 3138 6264 3133 6635  d82b723718bd13f5
00000030: 3331 3266 3965 3361 0a70 6172 656e 7420  312f9e3a.parent 
00000040: 6562 3462 6461 3632 3437 3161 3830 3365  eb4bda62471a803e
00000050: 3539 6665 3061 6338 3861 3530 6562 3663  59fe0ac88a50eb6c
00000060: 6535 3938 3233 6437 0a61 7574 686f 7220  e59823d7.author 
00000070: 4461 6e69 656c 204b 6e69 7474 6c2d 4672  Daniel Knittl-Fr
00000080: 616e 6b20 3c6b 6e69 7474 6c38 392b 6769  ank <knittl89+gi
00000090: 7440 676f 6f67 6c65 6d61 696c 2e63 6f6d  t@googlemail.com
000000a0: 3e20 3135 3531 3032 3131 3338 202b 3031  > 1551021138 +01
000000b0: 3030 0a63 6f6d 6d69 7474 6572 2044 616e  00.committer Dan
000000c0: 6965 6c20 4b6e 6974 746c 2d46 7261 6e6b  iel Knittl-Frank
000000d0: 203c 6b6e 6974 746c 3839 2b67 6974 4067   <knittl89+git@g
000000e0: 6f6f 676c 656d 6169 6c2e 636f 6d3e 2031  ooglemail.com> 1
000000f0: 3535 3130 3231 3133 3820 2b30 3130 300a  551021138 +0100.
00000100: 0a6d 6f76 696e 6720 7374 7566 660a       .moving stuff.
commit 259tree 1afedec6ec7fd631d82b723718bd13f5312f9e3a↲
parent eb4bda62471a803e59fe0ac88a50eb6ce59823d7↲
author Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551021138 +0100↲
committer Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551021138 +0100↲

moving stuff↲
  • commit object with 259 bytes
  • Null byte
  • Content
  • Tree reference: .git/objects/1a/fedec6ec7fd631d82b723718bd13f5312f9e3a
  • Parent commit reference: .git/objects/eb/4bda62471a803e59fe0ac88a50eb6ce59823d7
  • Author information
  • Committer information
  • Blank line
  • Commit message

Next commit ^{tree}

$ git rev-parse 189dbe5ef6a95867109b18cd44a6eb593120b9b5^{tree}
.git/objects/1a/fedec6ec7fd631d82b723718bd13f5312f9e3a (zlib)
00000000: 7472 6565 2033 3300 3430 3030 3020 7375  tree 33.40000 su
00000010: 6264 6972 0072 67a9 8ac1 9cdb 06f5 aedc  bdir.rg.........
00000020: e6cc 0a74 8e86 e1d0 03                   ...t.....

Next commit: subdir

.git/objects/72/67a98ac19cdb06f5aedce6cc0a748e86e1d003 (zlib)
00000000: 7472 6565 2032 3900 3130 3036 3434 2062  tree 29.100644 b
00000010: 008c 7e5a 667f 1b77 1847 fe88 c01c 3de3  ..~Zf..w.G....=.
00000020: 4413 a1b2 20                             D... 

Branch

$ git branch feature

🕒 10 minute break 💤

Feature: README

$ git checkout feature

$ >README echo 'readme file'
$ git add README
$ git commit -m 'commit on feature branch'
  • .git/HEAD content: ref: refs/heads/feature
  • .git/refs/heads/feature content: 68a9000a29eaa95b236955165f1b5fec795b84a1
  • .git/refs/heads/master content: 189dbe5ef6a95867109b18cd44a6eb593120b9b5

Master: CONTACT

$ git checkout master

$ >CONTACT echo 'knittl89+git@googlemail.com'
$ git add CONTACT
$ git commit -m 'Add contact information'
  • .git/HEAD content: ref: refs/heads/master
  • .git/refs/heads/master content: 6266d66bfc8f55c2ad41cff4e224e3cbf7f24317
  • .git/refs/heads/feature content: 68a9000a29eaa95b236955165f1b5fec795b84a1

Commit contact info

.git/objects/62/66d66bfc8f55c2ad41cff4e224e3cbf7f24317
commit 270␀tree f62a2c89224e0371614b8e10b7ef6064a95319af↲
parent 189dbe5ef6a95867109b18cd44a6eb593120b9b5↲
author Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551482695 +0100↲
committer Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551482695 +0100↲
↲
Add contact information↲

.git/objects/f6/2a2c89224e0371614b8e10b7ef6064a95319af
00000000: 7472 6565 2036 3800 3130 3036 3434 2043  tree 68.100644 C
00000010: 4f4e 5441 4354 003a f09e 7b97 ba19 c4f6  ONTACT.:..{.....
00000020: ad0a b2bf 98d5 b82a 4ed5 0534 3030 3030  .......*N..40000
00000030: 2073 7562 6469 7200 7267 a98a c19c db06   subdir.rg......
00000040: f5ae dce6 cc0a 748e 86e1 d003            ......t.....
  • regular, non-executable file: CONTACT (3af09e7b)
  • directory: subdir (7267a98a)

Tag 0.0.1

$ git tag 0.0.1

Merge Feature

$ git merge feature
commit 317␀tree c88eef15030fc09d2b33f46842aa556b70fbf1f1↲
parent 6266d66bfc8f55c2ad41cff4e224e3cbf7f24317parent 68a9000a29eaa95b236955165f1b5fec795b84a1↲
author Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551516724 +0100↲
committer Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551516724 +0100↲
↲
Merge branch 'feature'↲

Release 1.0.0

$ git tag -a -m 'Release 1!' 1.0.0
.git/objects/20/27878af6dcade24c1181985b2c52271fdaeddb
00000000: 7461 6720 3135 3600 6f62 6a65 6374 2036  tag 156.object 6
00000010: 3863 3239 6262 3639 6534 3334 6635 3839  8c29bb69e434f589
00000020: 3162 3261 3835 3335 6330 6137 3131 3839  1b2a8535c0a71189
00000030: 6331 6534 6538 320a 7479 7065 2063 6f6d  c1e4e82.type com
00000040: 6d69 740a 7461 6720 312e 302e 300a 7461  mit.tag 1.0.0.ta
00000050: 6767 6572 2044 616e 6965 6c20 4b6e 6974  gger Daniel Knit
00000060: 746c 2d46 7261 6e6b 203c 6b6e 6974 746c  tl-Frank <knittl
00000070: 3839 2b67 6974 4067 6f6f 676c 656d 6169  89+git@googlemai
00000080: 6c2e 636f 6d3e 2031 3535 3135 3137 3038  l.com> 155151708
00000090: 3520 2b30 3130 300a 0a52 656c 6561 7365  5 +0100..Release
000000a0: 2031 210a                                 1!.
tag 156object 68c29bb69e434f5891b2a8535c0a71189c1e4e82type commit↲
tag 1.0.0↲
tagger Daniel Knittl-Frank <knittl89+git@googlemail.com> 1551517085 +0100
Release 1!↲

Remote Add

$ git remote add origin git@github.com:knittl/test.git
.git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@github.com:knittl/test.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Push

git push origin -u master:master
.git/config
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git@github.com:knittl/test.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

Fetch

$ git fetch origin
.git/objects/c7/36a043d3b022ba8091e437533b2b624c163cc9
00000000: 636f 6d6d 6974 2032 3633 0074 7265 6520  commit 263.tree 
00000010: 3432 6438 3565 3066 3631 6337 3363 6364  42d85e0f61c73ccd
00000020: 3837 6534 6233 3735 3662 6230 3062 6262  87e4b3756bb00bbb
[…]       […]                                      […]

Fast Forward

$ git merge --ff-only origin/pr

🏆 BONUS: The Index

🔗 Or jump straight to sources & links →

The Index

.git/index
00000000: 4449 5243 0000 0002 0000 0003 5c79 bdaa  DIRC........\y..
00000010: 0915 c1e9 5c79 bdaa 0915 c1e9 0000 0806  ....\y..........
00000020: 0010 5103 0000 81a4 0000 03e8 0000 03e8  ..Q.............
00000030: 0000 001c 3af0 9e7b 97ba 19c4 f6ad 0ab2  ....:..{........
00000040: bf98 d5b8 2a4e d505 0007 434f 4e54 4143  ....*N....CONTAC
00000050: 5400 0000 5c7a 4434 107a 3eec 5c7a 4434  T...\zD4.z>.\zD4
00000060: 07a 3eec 0000 0806 0010 51a3 0000 81a4  .z>.......Q.....
00000070: 000 03e8 0000 03e8 0000 000c 0bb9 0114  ................
00000080: 4ae 6ccb f30f dbf8 470e ebde 0007 d398  D.l.....G.......
00000090: 006 5245 4144 4d45 0000 0000 5c72 b439  ..README....\r.9
000000a0: b64 1634 5c72 90d1 0f23 7b75 0000 0806  .d.4\r...#{u....
000000b0: 010 5106 0000 81a4 0000 03e8 0000 03e8  ..Q.............
000000c0: 000 0001 8c7e 5a66 7f1b 7718 47fe 88c0  .....~Zf..w.G...
000000d0: c3d e344 13a1 b220 0008 7375 6264 6972  .=.D... ..subdir
000000e0: f62 0000 5452 4545 0000 0038 0033 2031  /b..TREE...8.3 1
000000f0: ac8 8eef 1503 0fc0 9d2b 33f4 6842 aa55  .........+3.hB.U
00000100: b70 fbf1 f173 7562 6469 7200 3120 300a  kp...subdir.1 0.
00000110: 267 a98a c19c db06 f5ae dce6 cc0a 748e  rg............t.
00000120: 6e1 d003 bb88 9e97 2259 f1fd 0256 88ed  ........"Y...V..
00000130: 65c1 0fcb c41e 726f                      e.....ro

Index Entry

5c79 bdaa 0915 c1e9
5c79 bdaa 0915 c1e9
0000 0806 0010 5103
0000 81a4
0000 03e8 0000 03e8
0000 001c
3af0 9e7b 97ba 19c4 f6ad 0ab2 bf98 d5b8 2a4e d505
0007
434f 4e54 4143 5400
0000

Index Extensions

5452 4545
0000 0038

00
3320 310a
c88e ef15 030f c09d 2b33 f468 42aa 556b 70fb f1f1

73 7562 6469 7200
3120 300a
7267 a98a c19c db06 f5ae dce6 cc0a 748e 86e1 d003

Sources & Links