The blog promised

Git talk

Vokinloksar33 November 09, 2017 #git #tech #learning #kl00k

This is the archive of the git talk I gave at a share session at Klook.

Goal:

Note:

Ignored

Why git

source code control manage system used for linux kernel

What is git

Git Objects

Blob Object (Binary Large OBject)

    ~/git $ git init test
    Initialized empty Git repository in /home/octave/git/test/.git/
    ~/git $ cd test/
    .git
    ~/git/test (master #)$ find .git/objects/
    .git/objects/
    .git/objects/info
    .git/objects/pack
    ~/git/test (master #)$ echo 'test content' | git hash-object -w --stdin
    d670460b4b4aece5915caf5c68d12f560a9fe3e4
    ~/git/test (master #)$ find .git/objects/ -type f 
    .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
    
    ~/git/test (master #)$ git cat-file -t d670460b4b4aece5915caf5c68d12f560a9fe3e4
    blob
    ~/git/test (master #)$ git cat-file -p d670460b4b4aece5915caf5c68d12f560a9fe3e4
    test content
    ~/git/test (master #)$ echo 'version 1' > test.txt
    ~/git/test (master #%)$ git hash-object -w test.txt
    83baae61804e65cc73a7201a7252750c76066a30
    ~/git/test (master #%)$ echo 'version 2' > test.txt
    ~/git/test (master #%)$ git hash-object -w test.txt
    1f7a7a472abf3dd9643fd615f6da379c4acb3e3a
    ~/git/test (master #%)$ find .git/objects -type f
    .git/objects/83/baae61804e65cc73a7201a7252750c76066a30
    .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
    .git/objects/1f/7a7a472abf3dd9643fd615f6da379c4acb3e3a
    ~/git/test (master #%)$ git cat-file -p 83baae61804e65cc73a7201a7252750c76066a30
    version 1
    ~/git/test (master #%)$ git cat-file -p 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a
    version 2

Tree Object

    ~/git/test (master #%)$ git update-index --add --cacheinfo 100644 83baae61804e65cc73a7201a7252750c76066a30 test.txt
    ~/git/test (master *+)$ git write-tree
    d8329fc1cc938780ffdd9f94e0d364e0ea74f579
    ~/git/test (master *+)$ git cat-file -t d8329fc1cc938780ffdd9f94e0d364e0ea74f579
    tree
    ~/git/test (master *+)$ git cat-file -p d8329fc1cc938780ffdd9f94e0d364e0ea74f579
    100644 blob 83baae61804e65cc73a7201a7252750c76066a30	test.txt

    ~/git/test (master *+)$ echo 'new file' > new.txt
    ~/git/test (master *+%)$ git update-index --add --cacheinfo 100644 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a test.txt
    ~/git/test (master +%)$ git update-index --add new.txt

Your staging area now has the new version of test.txt as well as the new file new.txt. Write out that tree (recording the state of the staging area or index to a tree object) and see what it looks like:

    ~/git/test (master +)$ git write-tree
    0155eb4229851634a0f03eb265b69f5a2d56f341
    ~/git/test (master +)$ git cat-file -p 0155eb4229851634a0f03eb265b69f5a2d56f341
    100644 blob fa49b077972391ad58037050f2a75f74e3671e92	new.txt
    100644 blob 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a	test.txt

    ~/git/test (master +)$ git read-tree --prefix=whatever-you-name-it d8329fc1cc938780ffdd9f94e0d364e0ea74f579
    ~/git/test (master *+)$ git write-tree
    3c2b28b833b0951d4ea54f94bcc7b21b934ab640
    ~/git/test (master *+)$ git cat-file -p 3c2b28b833b0951d4ea54f94bcc7b21b934ab640
    100644 blob fa49b077972391ad58037050f2a75f74e3671e92	new.txt
    100644 blob 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a	test.txt
    040000 tree d8329fc1cc938780ffdd9f94e0d364e0ea74f579	whatever-you-name-it

Commit Object

    .git/objects/
    ├── 01
       └── 55eb4229851634a0f03eb265b69f5a2d56f341 tree v2
    ├── 1f
       └── 7a7a472abf3dd9643fd615f6da379c4acb3e3a blob 'version 2'
    ├── 3c
       └── 2b28b833b0951d4ea54f94bcc7b21b934ab640 tree v3
    ├── 83
       └── baae61804e65cc73a7201a7252750c76066a30 blob 'version 1'
    ├── d6
       └── 70460b4b4aece5915caf5c68d12f560a9fe3e4 blob 'test content'
    ├── d8
       └── 329fc1cc938780ffdd9f94e0d364e0ea74f579 tree v1
    ├── fa
       └── 49b077972391ad58037050f2a75f74e3671e92 blob 'new file'
    ├── info
    └── pack

    9 directories, 7 files

    ~/git/test (master *+)$ echo 'first commit' | git commit-tree d8329fc
    79f6bdef16b32cef42b1bde8973f07329b2398b1

    ~/git/test (master *+)$ git cat-file -p 79f6bdef16b32cef42b1bde8973f07329b2398b1
    tree d8329fc1cc938780ffdd9f94e0d364e0ea74f579
    author octave 
    committer octave 

    first commit


    ~/git/test (master *+)$ echo 'second commit' | git commit-tree 0155eb -p 79f6bdef16b32cef42b1bde8973f07329b2398b1
    414b938a2b89933461ffab680bd22f6d8dd0d9ca
    ~/git/test (master *+)$ echo 'third commit' | git commit-tree 3c2b28 -p 414b938a2b89933461ffab680bd22f6d8dd0d9ca
    845d6be1d937b48500230ca61981f686696273d8


    ~/git/test (master *+)$ git log --stat 845d6be1d937b48500230ca61981f686696273d8
    commit 845d6be1d937b48500230ca61981f686696273d8
    Author: octave 
    Date:   Thu Nov 9 11:31:00 2017 +0800

        third commit

    whatever-you-name-it/test.txt | 1 +
    1 file changed, 1 insertion(+)

    commit 414b938a2b89933461ffab680bd22f6d8dd0d9ca
    Author: octave 
    Date:   Thu Nov 9 11:30:07 2017 +0800

        second commit

    new.txt  | 1 +
    test.txt | 2 +-
    2 files changed, 2 insertions(+), 1 deletion(-)

    commit 79f6bdef16b32cef42b1bde8973f07329b2398b1
    Author: octave 
    Date:   Thu Nov 9 11:27:08 2017 +0800

        first commit

    test.txt | 1 +
    1 file changed, 1 insertion(+)

    .git/objects/
    ├── 01
       └── 55eb4229851634a0f03eb265b69f5a2d56f341
    ├── 1f
       └── 7a7a472abf3dd9643fd615f6da379c4acb3e3a
    ├── 3c
       └── 2b28b833b0951d4ea54f94bcc7b21b934ab640
    ├── 41
       └── 4b938a2b89933461ffab680bd22f6d8dd0d9ca
    ├── 79
       └── f6bdef16b32cef42b1bde8973f07329b2398b1
    ├── 83
       └── baae61804e65cc73a7201a7252750c76066a30
    ├── 84
       └── 5d6be1d937b48500230ca61981f686696273d8
    ├── d6
       └── 70460b4b4aece5915caf5c68d12f560a9fe3e4
    ├── d8
       └── 329fc1cc938780ffdd9f94e0d364e0ea74f579
    ├── fa
       └── 49b077972391ad58037050f2a75f74e3671e92
    ├── info
    └── pack

    12 directories, 10 files

How git works

Git doesn’t store data as a series of changesets or deltas, but instead as a series of snapshots.

.git

HEAD, INDEX, WORKING DIR

you can use reset to update part of the Index or the Working Directory with previously committed content this way.

https://git-scm.com/blog/2011/07/11/reset.html // this could be used as a comprehensive example.


































WTF






















Basics

Advanced

about error

Best Practice

https://sethrobertson.github.io/GitBestPractices/









QAs