사전 준비
● mkdir
● cd
● echo
● find
● tree
● cat
● shasum / openssl
● > (redirection)
● | (pipe)
Slide 10
Slide 10 text
Git 명령어
git
git help git
Git 명령어는 2가지 종류가 있습니다. 무엇일까요?
Slide 11
Slide 11 text
Git 명령어
git
git help git
Slide 12
Slide 12 text
Git 명령어
git
git help git
Slide 13
Slide 13 text
Git 명령어
git
git help git
Slide 14
Slide 14 text
No content
Slide 15
Slide 15 text
Porcelain
Slide 16
Slide 16 text
Porcelain
Plumbing
Slide 17
Slide 17 text
Git 의 계층 구조
고수준 명령어 (Porcelain)
Slide 18
Slide 18 text
Git 의 계층 구조
저수준 명령어 (Plumbing)
고수준 명령어 (Porcelain)
Slide 19
Slide 19 text
Git 의 계층 구조
내용 주소화 파일시스템
저수준 명령어 (Plumbing)
고수준 명령어 (Porcelain)
Slide 20
Slide 20 text
Git 의 계층 구조
내용 주소화 파일시스템
저수준 명령어 (Plumbing)
고수준 명령어 (Porcelain)
Slide 21
Slide 21 text
Git 저장소 생성하기
git init git-internal
cd git-internal
tree .git
Slide 22
Slide 22 text
Git 저장소 생성하기
git init git-internal
cd git-internal
tree .git
Slide 23
Slide 23 text
Git 저장소 생성하기
git init git-internal
cd git-internal
tree .git
Slide 24
Slide 24 text
내용 주소화 파일 시스템 (Content-addressable
Filesystem)
같은 내용에 대해 항상 같은 파일 주소를 가지는 파일 시스템
Slide 25
Slide 25 text
내용 주소화 파일 시스템 (Content-addressable
Filesystem)
같은 내용에 대해 항상 같은 파일 주소를 가지는 파일 시스템
echo -n "Buzzvil\n" | shasum
또는
echo -n "Buzzvil\n" | openssl dgst -sha1
Slide 26
Slide 26 text
내용 주소화 파일 시스템 (Content-addressable
Filesystem)
같은 내용에 대해 항상 같은 파일 주소를 가지는 파일 시스템
echo -n "Buzzvil\n" | shasum
또는
echo -n "Buzzvil\n" | openssl dgst -sha1
Slide 27
Slide 27 text
내용 주소화 파일 시스템 (Content-addressable
Filesystem)
같은 내용에 대해 항상 같은 파일 주소를 가지는 파일 시스템
운영체제의 파일 시스템
Git의 내용 주소화 파일 시스템
buzzvil
Buzzvil\n
14cd3c9a57ab8474dc07757829b1313a51a9eb29
Buzzvil\n
저장
불러오
기
Slide 28
Slide 28 text
Git의 내용 주소화 파일 시스템 살펴보기
echo -n "Buzzvil\n" > buzzvil
git add buzzvil
git commit -m "Initial commit"
Slide 29
Slide 29 text
Git의 내용 주소화 파일 시스템 살펴보기
git hash-object buzzvil
Slide 30
Slide 30 text
Git의 내용 주소화 파일 시스템 살펴보기
git hash-object buzzvil
Slide 31
Slide 31 text
Git의 내용 주소화 파일 시스템 살펴보기
git hash-object buzzvil
Slide 32
Slide 32 text
Git의 내용 주소화 파일 시스템 살펴보기
git cat-file -p bce5
Slide 33
Slide 33 text
Git의 내용 주소화 파일 시스템 살펴보기
git cat-file -p bce5
Slide 34
Slide 34 text
Git의 내용 주소화 파일 시스템 살펴보기
find .git/objects -type f
Slide 35
Slide 35 text
Git의 내용 주소화 파일 시스템 살펴보기
find .git/objects -type f
Slide 36
Slide 36 text
Git의 내용 주소화 파일 시스템 살펴보기
find .git/objects -type f
Slide 37
Slide 37 text
Git의 내용 주소화 파일 시스템 살펴보기
cat .git/objects/bc/e568648779a…
Slide 38
Slide 38 text
Git의 내용 주소화 파일 시스템 살펴보기
cat .git/objects/bc/e568648779a…
Slide 39
Slide 39 text
Git의 내용 주소화 파일 시스템 살펴보기
# unzlib.py
import sys
import zlib
with open(sys.argv[1], 'rb') as f:
print(zlib.decompress(f.read()))
wget byb.kr/unzlib.py
Slide 40
Slide 40 text
Git의 내용 주소화 파일 시스템 살펴보기
python3 unzlib.py .git/objects/bc/e56…
Slide 41
Slide 41 text
Git의 내용 주소화 파일 시스템 살펴보기
python3 unzlib.py .git/objects/bc/e56…
Slide 42
Slide 42 text
Git Object
● Blob
● Tree
● Commit
● Tag
구조
<타입> <본문 길이>\x00<본문>
Slide 43
Slide 43 text
Git Object - Blob
파일의 데이터를 저장하는 역할을 하는 object
blob <본문 길이>\x00<본문>
echo -n "blob 8\x00Buzzvil\n" | shasum
Slide 44
Slide 44 text
Git Object - Blob
파일의 데이터를 저장하는 역할을 하는 object
blob <본문 길이>\x00<본문>
echo -n "blob 8\x00Buzzvil\n" | shasum
Slide 45
Slide 45 text
Git Object - Blob
파일의 데이터를 저장하는 역할을 하는 object
blob <본문 길이>\x00<본문>
echo -n "blob 8\x00Buzzvil\n" | shasum
Slide 46
Slide 46 text
Git Object - 타입 얻기
git cat-file -t bce5
Slide 47
Slide 47 text
Git Object - 타입 얻기
git cat-file -t bce5
Slide 48
Slide 48 text
자주 쓸 명령어
find .git/objects -type f # git이 관리하는 object
목록
git cat-file -t bce5 # object 타입
python3 unzlib.py .git/objects/../…
# 압축만 풀고 살펴보기
git cat-file -p bce5 # object를 읽기 좋게 표시
Slide 49
Slide 49 text
Git Object - Tree
● Tree와 Blob을 배열의 형태로 가질 수 있음
● Tree와 Blob의 이름을 저장
Slide 50
Slide 50 text
Git Object - Tree
find .git/objects -type f
Slide 51
Slide 51 text
Git Object - Tree
find .git/objects -type f
Slide 52
Slide 52 text
Git Object - Tree
git cat-file -t 6a19
Slide 53
Slide 53 text
Git Object - Tree
git cat-file -t 6a19
Slide 54
Slide 54 text
Git Object - Tree
python3 unzlib.py .git/objects/6a/194…
Slide 55
Slide 55 text
Git Object - Tree
python3 unzlib.py .git/objects/6a/194…
Slide 56
Slide 56 text
Git Object - Tree
python3 unzlib.py .git/objects/6a/194…
<타입> <본문 길이>\x00<본문>
Git Object - Tag
Git의 Tag는 2가지가 있다.
● Annotated Tag ← 커밋처럼 메시지를 남기고, 서명을 할 수 있는 태그, object
● Lightweight Tag ← 버즈빌의 대부분 태그
Slide 85
Slide 85 text
Git Object - Tag
git tag -a v1.0 -m "First version"
git show v1.0
Slide 86
Slide 86 text
Git Object - Tag
git tag -a v1.0 -m "First version"
git show v1.0
Slide 87
Slide 87 text
Git Object - Tag
find .git/objects -type f
Slide 88
Slide 88 text
Git Object - Tag
find .git/objects -type f
Slide 89
Slide 89 text
Git Object - Tag
find .git/objects -type f
Slide 90
Slide 90 text
Git Object - Tag
git cat-file -t 3f91
Slide 91
Slide 91 text
Git Object - Tag
git cat-file -t 3f91
Slide 92
Slide 92 text
Git Object - Tag
python3 unzlib.py .git/objects/3f/911…
Slide 93
Slide 93 text
Git Object - Tag
python3 unzlib.py .git/objects/3f/911…
<타입> <본문 길이>\x00<본문>
Slide 94
Slide 94 text
Git Object - Tag
git cat-file -p 3f91
Slide 95
Slide 95 text
Git Object - Tag
git cat-file -p 3f91
Slide 96
Slide 96 text
Git Object - Tag
git tag -a company bce5 -m "Our company"
git show company
Slide 97
Slide 97 text
Git Object - Tag
git tag -a company bce5 -m "Our company"
git show company
Slide 98
Slide 98 text
Git Object - Tag
git cat-file -p company
Slide 99
Slide 99 text
Git Object - Tag
git cat-file -p company
Slide 100
Slide 100 text
Git Object - Tag
git cat-file -p company
Slide 101
Slide 101 text
Git 의 계층 구조
내용 주소화 파일시스템
저수준 명령어 (Plumbing)
고수준 명령어 (Porcelain)
Slide 102
Slide 102 text
Git Object
● Blob
● Tree
● Commit
● Tag
구조
<타입> <본문 길이>\x00<본문>
Slide 103
Slide 103 text
자주 쓴 명령어
find .git/objects -type f # git이 관리하는 object
목록
git cat-file -t bce5 # object 타입
python3 unzlib.py .git/objects/../…
# 압축만 풀고 살펴보기
git cat-file -p bce5 # object를 읽기 좋게 표시
Slide 104
Slide 104 text
전체 그림
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와 브랜치 살펴보기
echo -n "ref: refs/heads/master" > .git/HEAD
git branch
git show
또는 git symbolic-ref HEAD refs/heads/master
Slide 119
Slide 119 text
HEAD와 브랜치 살펴보기
echo -n "ref: refs/heads/master" > .git/HEAD
git branch
git show
또는 git symbolic-ref HEAD refs/heads/master
Slide 120
Slide 120 text
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
Slide 121
Slide 121 text
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
Slide 122
Slide 122 text
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
Slide 123
Slide 123 text
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
Slide 124
Slide 124 text
Tag 살펴보기
git tag v0.0.1 develop
find .git/refs/tags -type f
Slide 125
Slide 125 text
Tag 살펴보기
git tag v0.0.1 develop
find .git/refs/tags -type f
Slide 126
Slide 126 text
Tag 살펴보기
find .git/refs/tags -type f -print -exec cat {} \;
Slide 127
Slide 127 text
Tag 살펴보기
find .git/refs/tags -type f -print -exec cat {} \;
Slide 128
Slide 128 text
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
Slide 129
Slide 129 text
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
Slide 130
Slide 130 text
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
Slide 131
Slide 131 text
HEAD와 브랜치 살펴보기
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…
Slide 132
Slide 132 text
HEAD와 브랜치 살펴보기
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…
Slide 133
Slide 133 text
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
Slide 134
Slide 134 text
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
Slide 135
Slide 135 text
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
Slide 136
Slide 136 text
전체 그림
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
Slide 137
Slide 137 text
.git 살펴보기
tree .git
Slide 138
Slide 138 text
.git 살펴보기
tree .git
Slide 139
Slide 139 text
index 살펴보기
git status
xxd .git/index
Slide 140
Slide 140 text
index 살펴보기
git status
xxd .git/index
https://mincong.io/2018/04/28/git-index/
Slide 141
Slide 141 text
참고 자료
● 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/