Etc.

git log, cat-file, rebase, reset, reflog

Accept 2025. 7. 31. 01:23

기본 정리

* 총 4가지 객체로 구성 commit, tree, blob, tag


git log를 통한 커밋 이력 확인

* git log --oneline --graph --all

-> Mac의 find .git/objects -type f을 통해 git hash(7자리)와 .git/objects 파일 비교 가능

 


git cat-file을 통한 커밋 정보 확인

* git cat-file -p [hash명] : tree, 작성자, 저장 시점, 커밋 메시지 등 확인 가능, hash 내용 출력

(commit, tree, blob 등의 hash를 입력해서 각 hash의 타입 확인 가능)

 

* git cat-file -p [태그명] : 태그 정보 확인

 

* git cat-file -t [hash명] : 타입 출력

(commit, tree, blob, tag의 hash를 입력해서 각 hash의 타입 확인 가능)


특정 hash의 상세 정보 확인(1번은 Mac OS 기준)

1. find .git/objects -type f : 전체 파일 목록 확인

2. git cat-file -p [hash명]


git rebase 방법

git rebase [리베이스하고 싶은 브랜치명]

git rebase -i [스쿼시하고 싶은 hash id]

* rebase는 원격 저장소 push 전 로컬 환경의 커밋 히스토리를 정리하기 위한 용도로 활용


잘못 reset, rebase 시 원복 방법

1-1. git reset --hard [reset 하고 싶은 hash id]

1-2. git rebase [리베이스하고 싶은 브랜치명]

2. git reflog

3. git reset --hard [reflog에서 확인한 원복하고 싶은 지점의 hash id]

* reflog는 로컬 환경에만 저장되며, 기본 90일 보존되지만 사라진 히스토리에 대해선 30일만 보존됨