Git Commit

✒️ 2025-07-26 20:38 내용 수정


참고 자료 : Git commit, Geeksforgeeks What is Git Commit

특정 시점에 대한 스냅샷

Commit 구조

  1. 파일 내용을 Git 객체(blob)로 저장한다.
  2. 객체 식별자인 SHA-1 해시를 생성한다.
  3. 커밋은 Tree 객체를 참조하며, 그 Tree가 BLOB 객체들을 참조한다.

기본 흐름

# 변경된 파일 전체를 staging area에 추가
git add .

# 일부만 추가
git add <filename>
git commit
git commit -m "initial commit"

Commit 옵션

옵션 설명 사용 예시
-m, --message 커밋 메시지를 바로 입력.
메시지가 없으면 편집기 오픈
git commit -m "Fix bug"
-a, --all 추적 중인(tracked) 수정/삭제된 파일 자동 staging → 바로 커밋 (새 파일 제외) git commit -a -m "Update files"
-am 조합 -a-m 조합 커맨드로 staging 없이 커밋 메시지 포함 커밋 git commit -am "Quick update"
--amend 가장 최근 커밋 내용을 수정
(새 커밋이 아닌 이전 커밋 덮어쓰기)
git add file && git commit --amend -m "Updated"
--no-edit --amend와 함께 사용하여 메시지 편집 없이 내용만 수정 git commit --amend --no-edit
-p, --patch interactive 모드로 커밋할 변경 hunk를 수동 선택 git commit -p -m "Selective commit"
--reuse-message/-C 기존 커밋 메시지와 author 정보를 재사용 git commit -C <commit>
--reedit-message/-c 기존 메시지를 편집해서 새 커밋 생성 git commit -c <commit>
--fixup 특정 커밋을 정정하는 "fixup!" 커밋 생성
(rebase autosquash 지원)
git commit --fixup=<commit>
--squash 특정 커밋을 합치는 "squash!" 커밋 생성
(rebase autosquash 지원)
git commit --squash=<commit>
--reset-author --amend 등과 함께 사용해 author 정보를 현재 committer로 재설정 git commit --amend --reset-author
-F, --file 지정한 파일의 내용을 커밋 메시지로 사용 git commit -F msg.txt
--author 커밋 작성자(author)를 명시적으로 지정 git commit --author="Jane Doe <jane@example.com>"
--date 커밋의 작성 날짜를 지정된 값으로 설정 git commit --date="2025-07-26"
-S, --gpg-sign GPG 키로 커밋 서명.
키 ID는 옵션 뒤에 붙여 지정 가능
git commit -S 또는 --gpg-sign=<key>
--no-gpg-sign 서명 옵션을 무시하고 커밋 생성 (config 우선권 해제) git commit --no-gpg-sign
--dry-run 실제 커밋 없이 어떤 파일이 포함될지 미리 보여줌 git commit --dry-run
--verbose, -v 커밋 메시지 작성 시 변경 diff를 함께 보여줌 git commit -v
--status / --no-status 커밋 메시지 템플릿에 git status 결과 포함 또는 제외 git commit --status
-q, --quiet 커밋 요약 메시지를 출력하지 않음 git commit -q -m "..."
-i, --include 지정한 경로명만 커밋.
staging 인덱스 내용 무시함
git commit file1.txt
-u, --untracked-files 커밋 메시지 템플릿에 추적되지 않은 파일 보여주기 (mode 지정 가능) git commit -u=all

Commit message convention

<타입>(옵션:모듈): <변경 요약>

<변경 상세 설명> (선택 사항)
feat(login): 로그인 실패 시 메시지 추가

사용자가 로그인에 실패했을 때, 오류 메시지를 UI에 표시하도록 수정함

메시지 타입

타입 설명
feat 새로운 기능 추가
fix 버그 수정
docs 문서 수정 (README 등)
style 코드 스타일 수정 (세미콜론, 공백 등)
refactor 코드 리팩토링 (기능 변화 없음)
test 테스트 코드 추가 또는 수정
chore 빌드 설정, 패키지 매니저 설정 등 기타 작업
perf 성능 개선

모듈/영역 표기

예시

fix(auth): Prevent null pointer exception on login

Validate that email and password inputs are not null before
processing authentication logic to avoid server errors.
Fixes #456.
docs: Update README with setup and usage

Add instructions for local environment setup, additional
configuration notes, and example usage for new contributors.