C.W.K.
Stream
Lesson 04 of 05 · published

commit, parent, DAG

~20 min · dag, commit-graph

Level 0Untracked 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

commit 은 노드, branch 는 pointer

commit 이 snapshot 이라는 걸 받아들였으면 다음은 'snapshot 들이 어떻게 연결되는가' 야. 모든 commit (첫 번째 제외) 은 자기 parent 의 hash 를 기록해. merge commit 은 parent 가 둘이야. 그래서 결과는 Directed Acyclic Graph 야: directed (link 는 과거 한 방향), acyclic (link 따라가다 출발점 못 돌아옴), graph (병렬 branch + merge 가 진짜 graph topology 만들어, line 이 아니라).

그림 그려봐. A ← B ← C ← Dmain 의 linear chain 이야. B 에서 feature 분기해서 E ← F 추가. graph 가 갈라져. featuremain 으로 merge 하면 parent 둘인 G 가 생겨 — DF. 미래의 history walk 는 G 에서 양쪽 parent 어느 쪽으로든 모든 과거 작업에 닿을 수 있어. 지워지는 거 없고 덮어쓰는 거 없어. graph 가 그냥 자라.

branch 와 tag 는 hash 하나 든 41 byte 파일이야. feature 만들기 = 파일 하나 쓰기. switch 하면 HEAD 가 그걸 가리키게 돼. 지우면 pointer 가 사라지지만 commit 은 남아 있고, 다른 ref 가 안 가리키면 결국 Git GC 가 정리해. 'branch 가 왜 그렇게 싸지?' 의 답이야 — 복사할 게 거의 없어.

강력한 Git 명령들 — log, blame, bisect, rebase, cherry-pick — 다 graph 연산이야. 명령을 graph instruction 으로 읽기 시작하면 이름이 임의롭지 않게 보여. git log feature..main 은 'main 에서 도달 가능하지만 feature 에서는 도달 불가능한 commit 들' 이야. DAG 위 set difference 인 거지.

Code

아무 repo 의 실제 DAG 시각화·bash
# 모든 branch 의 ASCII graph
git log --oneline --graph --decorate --all

# 최근 20 노드, author + 날짜 포함
git log --oneline --graph --decorate --all --pretty='%h %ad %an %d %s' --date=short -n 20

# commit 하나의 parent 보기
git cat-file -p HEAD | head -3
branch 와 tag 는 pointer, 폴더 아니야·bash
# main 이 실제로 가리키는 건?
cat .git/refs/heads/main

# HEAD 는?
cat .git/HEAD

# ref 한꺼번에 보기
git for-each-ref --sort=committerdate \
  --format='%(refname:short) -> %(objectname:short)'

External links

Exercise

scratch repo 에 main 에 commit 네 개 만들고, feature 분기해서 commit 두 개, main 으로 돌아와 commit 하나 더, 그 다음 feature 를 merge. git log --oneline --graph --decorate --all 실행. parent 가 둘인 commit 어느 거인지 짚어. 그 다음 git log main..feature 가 graph 에 대해 뭘 말하는지 한 줄로 설명해.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.