Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git 해부하기 2 + 3

Buzzvil
August 19, 2022

Git 해부하기 2 + 3

Buzzvil

August 19, 2022
Tweet

More Decks by Buzzvil

Other Decks in Programming

Transcript

  1. Git 해부하기2+3
    2022-08-19
    Brice

    View full-size slide

  2. 1. git init git-internal
    2. cd git-internal
    3. echo -n "Buzzvil\n" > buzzvil
    4. git add buzzvil
    5. git commit -m "Initial commit"
    6. mkdir jamsil
    7. echo -n "Buzzvil\n" > jamsil/buzzvil
    8. git add jamsil
    9. git commit -m "Add Jamsil"
    10. git tag -a v1.0 -m "First version"
    11. git tag -a company bce5 -m "Our company"
    지난 시간에 했던 git-internal
    상태를 복원하는 작업입니다.
    git-internal 삭제하신 분들은
    1번부터
    삭제하지 않으신 분들은 빠진
    부분을 진행해주시면 됩니다.
    (아마 11번만 하시면 됩니다.)

    View full-size slide

  3. 부트캠프 Git
    https://buzzvil.atlassian.net/wiki/spaces/DEV/pages/2875883762/Git

    View full-size slide

  4. Git 해부하기2 - 참조
    2022-08-19
    Brice

    View full-size slide

  5. Git 의 계층 구조
    내용 주소화 파일시스템
    저수준 명령어 (Plumbing)
    고수준 명령어 (Porcelain)

    View full-size slide

  6. Git Object
    ● Blob
    ● Tree
    ● Commit
    ● Tag
    구조
    <타입> <본문 길이>\x00<본문>

    View full-size slide

  7. 자주 쓴 명령어
    find .git/objects -type f # git이 관리하는 object
    목록
    git cat-file -t bce5 # object 타입
    python3 unzlib.py .git/objects/../…
    # 압축만 풀고 살펴보기
    git cat-file -p bce5 # object를 읽기 좋게 표시

    View full-size slide

  8. 전체 그림
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91

    View full-size slide

  9. 1. git init git-internal
    2. cd git-internal
    3. echo -n "Buzzvil\n" > buzzvil
    4. git add buzzvil
    5. git commit -m "Initial commit"
    6. mkdir jamsil
    7. echo -n "Buzzvil\n" > jamsil/buzzvil
    8. git add jamsil
    9. git commit -m "Add Jamsil"
    10. git tag -a v1.0 -m "First version"
    11. git tag -a company bce5 -m "Our company"

    View full-size slide

  10. 전체 그림
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91

    View full-size slide

  11. Git 저장소 살펴보기
    tree .git

    View full-size slide

  12. Refs
    ● 브랜치: master, …
    ● 태그: v0.0.1, …
    ● Symbolic Refs: HEAD, …

    View full-size slide

  13. HEAD 살펴보기
    cat .git/HEAD

    View full-size slide

  14. HEAD 살펴보기
    cat .git/HEAD

    View full-size slide

  15. 브랜치 살펴보기
    cat .git/refs/heads/master

    View full-size slide

  16. 브랜치 살펴보기
    cat .git/refs/heads/master
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    object
    d837
    3f91

    View full-size slide

  17. 브랜치 살펴보기
    git cat-file -p master # parent 얻기
    echo -n "82a26d…" > .git/refs/heads/develop
    git branch
    또는 git update-ref refs/heads/develop 82a26d…

    View full-size slide

  18. 브랜치 살펴보기
    git cat-file -p master # parent 얻기
    echo -n "82a26d…" > .git/refs/heads/develop
    git branch
    또는 git update-ref refs/heads/develop 82a26d…

    View full-size slide

  19. 브랜치 살펴보기
    git switch develop
    git show

    View full-size slide

  20. 브랜치 살펴보기
    git switch develop
    git show

    View full-size slide

  21. HEAD와 브랜치 살펴보기
    cat .git/HEAD

    View full-size slide

  22. HEAD와 브랜치 살펴보기
    cat .git/HEAD

    View full-size slide

  23. HEAD와 브랜치 살펴보기
    cat .git/HEAD

    View full-size slide

  24. HEAD와 브랜치 살펴보기
    echo -n "ref: refs/heads/master" > .git/HEAD
    git branch
    git show
    또는 git symbolic-ref HEAD refs/heads/master

    View full-size slide

  25. HEAD와 브랜치 살펴보기
    echo -n "ref: refs/heads/master" > .git/HEAD
    git branch
    git show
    또는 git symbolic-ref HEAD refs/heads/master

    View full-size slide

  26. HEAD와 브랜치 살펴보기
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91

    View full-size slide

  27. HEAD와 브랜치 살펴보기
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    HEAD

    View full-size slide

  28. HEAD와 브랜치 살펴보기
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    HEAD heads/master

    View full-size slide

  29. HEAD와 브랜치 살펴보기
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    HEAD heads/master
    heads/develop

    View full-size slide

  30. Tag 살펴보기
    git tag v0.0.1 develop
    find .git/refs/tags -type f

    View full-size slide

  31. Tag 살펴보기
    git tag v0.0.1 develop
    find .git/refs/tags -type f

    View full-size slide

  32. Tag 살펴보기
    find .git/refs/tags -type f -print -exec cat {} \;

    View full-size slide

  33. Tag 살펴보기
    find .git/refs/tags -type f -print -exec cat {} \;

    View full-size slide

  34. Tag 살펴보기
    find .git/refs/tags -type f -print -exec cat {} \;
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    heads/develop
    heads/master
    HEAD

    View full-size slide

  35. Tag 살펴보기
    find .git/refs/tags -type f -print -exec cat {} \;
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    heads/develop
    heads/master
    HEAD
    tags/v1.0
    tags/company

    View full-size slide

  36. Tag 살펴보기
    find .git/refs/tags -type f -print -exec cat {} \;
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    heads/develop
    heads/master
    HEAD
    tags/v0.0.1
    tags/v1.0
    tags/company

    View full-size slide

  37. Tag 살펴보기
    git cat-file -p 2ed8 # jamsil 해시
    구하기
    echo -n "6a19…" > .git/refs/tags/jamsil
    git tag
    git show jamsil
    git show company
    또는 git update-ref refs/tags/jamsil 6a19…

    View full-size slide

  38. Tag 살펴보기
    git cat-file -p 2ed8 # jamsil 해시
    구하기
    echo -n "6a19…" > .git/refs/tags/jamsil
    git tag
    git show jamsil
    git show company
    또는 git update-ref refs/tags/jamsil 6a19…

    View full-size slide

  39. Tag 살펴보기
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    heads/develop
    heads/master
    HEAD
    tags/v1.0
    tags/v0.0.1
    tags/company

    View full-size slide

  40. Tag 살펴보기
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    heads/develop
    heads/master
    HEAD
    tags/v1.0
    tags/v0.0.1
    tags/company

    View full-size slide

  41. Tag 살펴보기
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    heads/develop
    heads/master
    HEAD
    tags/v1.0
    tags/v0.0.1
    tags/company
    tags/jamsil

    View full-size slide

  42. 전체 그림
    Buzzvil\n
    6a19 bce5
    Initial
    commit
    Add
    Jamsil
    82a2
    442d
    parent
    tree
    tree
    2ed8
    company
    v1.0
    jamsil
    buzzvil
    buzzvil
    object
    object
    d837
    3f91
    heads/develop
    heads/master
    HEAD
    tags/v1.0
    tags/company
    tags/jamsil
    tags/v0.0.1

    View full-size slide

  43. Git 해부하기3
    과정 들여다보기
    2022-08-19
    Brice

    View full-size slide

  44. git의 세 가지 상태

    View full-size slide

  45. 목차
    1. 파일 생성하기
    2. 파일을 git에 등록하기
    3. index 파일 살펴보기
    4. tree 만들기
    5. commit 만들기
    6. branch 업데이트하기

    View full-size slide

  46. .git 초기화하기
    cd ..
    rm -rf git-internal
    git init git-internal
    cd git-internal

    View full-size slide

  47. .git 살펴보기
    tree .git

    View full-size slide

  48. .git 살펴보기
    tree .git

    View full-size slide

  49. 파일 생성하기
    echo -n "Buzzvil\n" > buzzvil
    git status

    View full-size slide

  50. 파일 생성하기
    echo -n "Buzzvil\n" > buzzvil
    git status

    View full-size slide

  51. 파일 생성하기
    tree .git

    View full-size slide

  52. 파일을 git에 등록하기
    git add buzzvil
    git status
    tree .git

    View full-size slide

  53. 파일을 git에 등록하기
    git add buzzvil
    git status
    tree .git

    View full-size slide

  54. 파일을 git에 등록하기
    git add buzzvil
    git status
    tree .git

    View full-size slide

  55. 파일을 git에 등록하기
    git add buzzvil
    git status
    tree .git

    View full-size slide

  56. git add <파일>
    ● index 파일이 생긴다.
    ● 파일의 blob이 생긴다.

    View full-size slide

  57. index 살펴보기
    xxd .git/index

    View full-size slide

  58. index 살펴보기
    xxd .git/index

    View full-size slide

  59. index 살펴보기
    xxd .git/index
    추가 상세 정보:

    View full-size slide

  60. index 살펴보기
    git ls-files --stage

    View full-size slide

  61. index 살펴보기
    git ls-files --stage

    View full-size slide

  62. tree 만들기
    git write-tree

    View full-size slide

  63. tree 만들기
    git write-tree

    View full-size slide

  64. tree 만들기
    git write-tree
    git cat-file -t 6a1942…

    View full-size slide

  65. tree 만들기
    git write-tree
    git cat-file -t 6a1942…

    View full-size slide

  66. tree 만들기
    git write-tree
    git cat-file -t 6a1942…
    git cat-file -p 6a1942…

    View full-size slide

  67. tree 만들기
    git write-tree
    git cat-file -t 6a1942…
    git cat-file -p 6a1942…

    View full-size slide

  68. commit 만들기
    echo "Initial commit" | git commit-tree 6a1942

    View full-size slide

  69. commit 만들기
    echo "Initial commit" | git commit-tree 6a1942

    View full-size slide

  70. commit 만들기
    echo "Initial commit" | git commit-tree 6a1942
    git cat-file -t 30423d…
    git cat-file -p 30423d…

    View full-size slide

  71. commit 만들기
    echo "Initial commit" | git commit-tree 6a1942
    git cat-file -t 30423d…
    git cat-file -p 30423d…

    View full-size slide

  72. git 상태 살펴보기
    git status

    View full-size slide

  73. git 상태 살펴보기
    git status

    View full-size slide

  74. branch 업데이트하기
    cat refs/heads/master
    git update-ref refs/heads/master 30423d…
    cat refs/heads/master

    View full-size slide

  75. branch 업데이트하기
    cat refs/heads/master
    git update-ref refs/heads/master 30423d…
    cat refs/heads/master

    View full-size slide

  76. git 상태 살펴보기
    git status

    View full-size slide

  77. 참고 자료
    ● https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
    ● https://shafiul.github.io/gitbook/1_the_git_object_model.html
    ● https://scribe.rip/geekculture/a-beginners-guide-to-git-and-git-internals-1e7dcd89d65e
    ● https://scribe.rip/geekculture/git-branching-made-easy-1cc894b9fd03
    ● https://stackoverflow.com/questions/737673/how-to-read-the-mode-field-of-git-ls-trees-output
    ● https://mincong.io/2018/04/28/git-index/
    ● https://codewords.recurse.com/issues/two/git-from-the-inside-out
    ● https://cuddly-octo-palm-tree.com/posts/2021-09-19-git-elements/
    ● https://www.leshenko.net/p/ugit/

    View full-size slide

  78. 감사합니다.
    cd .. && rm -rvf git-internal

    View full-size slide