본문 바로가기
Git

Git의 원리] 8. git tag 원리

by Fastlane 2022. 9. 8.
728x90
반응형

tag를 생성할 때, git내부적으로 tag가 어떻게 관리되는지 확인해보자. 

# git 초기화한다. 
$ git init
Initialized empty Git repository in C:/Project/git_test/.git/

# commit을 생성한다. 
$ vim f1.txt

$ git add f1.txt
warning: LF will be replaced by CRLF in f1.txt.
The file will have its original line endings in your working directory

$ git commit -m 1
[master (root-commit) d15d55a] 1
 1 file changed, 1 insertion(+)
 create mode 100644 f1.txt

# 최신 commit에 tag를 지정한다. 
$ git tag 1.0.0

$ git log
commit d15d55a862692b4a4ea614a21707d560d4fb90ba (HEAD -> master, tag: 1.0.0)
Author: 
Date:   Thu Sep 8 16:00:02 2022 +0900

    1

 

.git\refs\tags 경로에 1.0.0 파일이 생성되었고 파일 안에는 commit hash id가 저장되어 있다. 

그렇다면 command line을 통하지 않고 해당 경로에 직접 파일을 추가해서 tag를 생성해보자. 

1.0.0파일을 그대로 복사하고 파일명을 1.1.0으로 수정해보자. 

첫번째 commit에 tag가 추가된 것을 확인할 수 있다. 

$ git log
commit d15d55a862692b4a4ea614a21707d560d4fb90ba (tag: 1.1.0, tag: 1.0.0)
Author: 
Date:   Thu Sep 8 16:00:02 2022 +0900

    1

annotated tag는 어떻게 관리되는지 확인해보자. 

# 두번째 commit을 생성해보자. 
$ vim f1.txt

$ git commit -am 2
warning: LF will be replaced by CRLF in f1.txt.
The file will have its original line endings in your working directory
[master 3cea639] 2
 1 file changed, 1 insertion(+)

# 이번엔 annotated tag를 지정하자. 
$ git tag -a 1.1.1 -m 'bug fix'

.git 하위에 파일이 2개가 추가되었다. 

첫번째 파일은 .git\refs\tags 경로 하위에 1.1.1파일이 추가되었고 파일안에는 object hash id(8f17814c1db0de765223e6338f3f1daae0cf5cb9)가 저장되어 있다. 

 

그리고 해당 object 경로(.git\objects\8f)에 17814c1db0de765223e6338f3f1daae0cf5cb9파일이 추가되어 있다. 

 

# object 파일에는 annotated tag의 상세설명이 들어있다. 
$ git cat-file -p 8f17814c1db0de765223e6338f3f1daae0cf5cb9
object 3cea6396ca6002a72f87ad6b046a7be7b4fb9f0c
type commit
tag 1.1.1
tagger

bug fix

# 해당 object type은 tag이다. 
$ git cat-file -t 8f17814c1db0de765223e6338f3f1daae0cf5cb9
tag

 

light weight tag는 해당 commit id만 저장되어 있는 파일이 1개 생성되고, annotated tag는 tag object hash id가 저장된 파일 1개와 tag정보가 저장된 tag object 파일이 1개 생성된다. 

728x90
반응형

댓글