Slide 1

Slide 1 text

Git 해부하기 2022-07-15 Brice

Slide 2

Slide 2 text

손 들어봅시다: 나는 Git이 무섭다?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

사전 준비 ● terminal ● git ● python3

Slide 9

Slide 9 text

사전 준비 ● 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<본문>

Slide 57

Slide 57 text

Git Object - Tree python3 unzlib.py .git/objects/6a/194… <타입> <본문 길이>\x00<본문> \x00 \x00 \x00 …

Slide 58

Slide 58 text

Git Object - Tree git cat-file -p 6a19 또는 git ls-tree 6a19

Slide 59

Slide 59 text

Git Object - Tree git cat-file -p 6a19 또는 git ls-tree 6a19

Slide 60

Slide 60 text

Git Object - Tree (root) buzzvil 6a19 bce5

Slide 61

Slide 61 text

Git Object - Tree in Tree mkdir jamsil echo -n "Buzzvil\n" > jamsil/buzzvil git add jamsil git commit -m "Add Jamsil" (root) jamsil buzzvil buzzvil 6a19 bce5

Slide 62

Slide 62 text

Git Object - Tree in Tree find .git/objects -type f

Slide 63

Slide 63 text

Git Object - Tree in Tree find .git/objects -type f

Slide 64

Slide 64 text

find .git/objects -type f Git Object - Tree in Tree (root) jamsil buzzvil buzzvil 6a19 bce5

Slide 65

Slide 65 text

git cat-file -t 2ed8 Git Object - Tree in Tree (root) jamsil buzzvil buzzvil 6a19 bce5

Slide 66

Slide 66 text

git cat-file -t 2ed8 Git Object - Tree in Tree (root) jamsil buzzvil buzzvil 6a19 bce5

Slide 67

Slide 67 text

git cat-file -p 2ed8 Git Object - Tree in Tree (root) jamsil buzzvil buzzvil 6a19 bce5

Slide 68

Slide 68 text

git cat-file -p 2ed8 Git Object - Tree in Tree (root) jamsil buzzvil buzzvil 6a19 bce5

Slide 69

Slide 69 text

git cat-file -p 2ed8 Git Object - Tree in Tree (root) jamsil buzzvil buzzvil 6a19 bce5 2ed8 6a19 bce5

Slide 70

Slide 70 text

Git Object - Commit Git을 사용하면서 수시로 만드는 바로 그 commit을 나타내는 object

Slide 71

Slide 71 text

Git Object - Commit Git을 사용하면서 수시로 만드는 바로 그 commit을 나타내는 object

Slide 72

Slide 72 text

Git Object - Commit git cat-file -t 82a2

Slide 73

Slide 73 text

Git Object - Commit git cat-file -t 82a2

Slide 74

Slide 74 text

Git Object - Commit python3 unzlib.py .git/objects/82/a26…

Slide 75

Slide 75 text

Git Object - Commit python3 unzlib.py .git/objects/82/a26… <타입> <본문 길이>\x00<본문>

Slide 76

Slide 76 text

Git Object - Commit git cat-file -p 82a2

Slide 77

Slide 77 text

Git Object - Commit git cat-file -p 82a2

Slide 78

Slide 78 text

Git Object - Commit git cat-file -t 442d

Slide 79

Slide 79 text

Git Object - Commit git cat-file -t 442d

Slide 80

Slide 80 text

Git Object - Commit git cat-file -p 442d

Slide 81

Slide 81 text

Git Object - Commit git cat-file -p 442d

Slide 82

Slide 82 text

Git Object - Commit (root) jamsil buzzvil buzzvil bce5 2ed8 6a19 bce5

Slide 83

Slide 83 text

Git Object - Commit (root) jamsil buzzvil buzzvil bce5 2ed8 6a19 bce5

Slide 84

Slide 84 text

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

Slide 105

Slide 105 text

Git 저장소 살펴보기 tree .git

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

HEAD 살펴보기 cat .git/HEAD

Slide 108

Slide 108 text

HEAD 살펴보기 cat .git/HEAD

Slide 109

Slide 109 text

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

Slide 110

Slide 110 text

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

Slide 111

Slide 111 text

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

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

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

Slide 114

Slide 114 text

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

Slide 115

Slide 115 text

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

Slide 116

Slide 116 text

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

Slide 117

Slide 117 text

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

Slide 118

Slide 118 text

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/

Slide 142

Slide 142 text

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