$30 off During Our Annual Pro Sale. View Details »

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. 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번만 하시면 됩니다.)
  2. Git Object • Blob • Tree • Commit • Tag

    구조 <타입> <본문 길이>\x00<본문>
  3. 자주 쓴 명령어 find .git/objects -type f # git이 관리하는

    object 목록 git cat-file -t bce5 # object 타입 python3 unzlib.py .git/objects/../… # 압축만 풀고 살펴보기 git cat-file -p bce5 # object를 읽기 좋게 표시
  4. 전체 그림 Buzzvil\n 6a19 bce5 Initial commit Add Jamsil 82a2

    442d parent tree tree 2ed8 company v1.0 jamsil buzzvil buzzvil object object d837 3f91
  5. 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"
  6. 전체 그림 Buzzvil\n 6a19 bce5 Initial commit Add Jamsil 82a2

    442d parent tree tree 2ed8 company v1.0 jamsil buzzvil buzzvil object object d837 3f91
  7. 브랜치 살펴보기 git cat-file -p master # parent 얻기 echo

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

    -n "82a26d…" > .git/refs/heads/develop git branch 또는 git update-ref refs/heads/develop 82a26d…
  9. HEAD와 브랜치 살펴보기 echo -n "ref: refs/heads/master" > .git/HEAD git

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

    branch git show 또는 git symbolic-ref HEAD refs/heads/master
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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…
  19. 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…
  20. 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
  21. 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
  22. 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
  23. 전체 그림 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
  24. 목차 1. 파일 생성하기 2. 파일을 git에 등록하기 3. index

    파일 살펴보기 4. tree 만들기 5. commit 만들기 6. branch 업데이트하기
  25. commit 만들기 echo "Initial commit" | git commit-tree 6a1942 git

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

    cat-file -t 30423d… git cat-file -p 30423d…
  27. 참고 자료 • 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/