본문 바로가기
C.W.K.
Stream
Lesson 01 of 05 · published

amend, fixup, autosquash

~22 min · amend, fixup

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

공개하기 전에 amend, fixup, autosquash로 다듬어

실제 코딩 과정은 지저분해. 기능 commit 뒤 주석 오타를 찾고, 빠뜨린 test를 보태고, docstring까지 고치게 되지. 이 과정을 네 commit으로 그대로 push하면 이력이 산만해져. 공개하기 전에 로컬 이력을 정리해 main에 올라갈 때는 한 관심사가 한 이야기로 읽히게 해. 그때 쓰는 도구가 --amend, --fixup, --autosquash야.

git commit --amend는 가장 최근 commit을 이전 변경과 현재 staged 변경을 합친 새 commit으로 교체해. 원본 hash 대신 새 hash가 그 자리에 와. 파일을 add하지 않았거나 message를 고쳐야 할 때 알맞아. amend는 message 편집기를 열고, --no-edit를 붙이면 기존 message를 그대로 써.

git commit --fixup <hash>는 나중에 대상 commit 안으로 합칠 보정 commit을 만들어. 일반 commit처럼 다룰 수 있지만 '나중에 대상 commit을 amend할 보정'이라는 metadata가 붙어. git rebase -i --autosquash는 그 표시를 읽어 fixup commit을 대상 옆으로 옮기고 squash하도록 interactive rebase를 배열해. 손으로 순서를 바꾸거나 message를 다시 쓸 필요가 없어. git config --global rebase.autosquash true를 두면 모든 interactive rebase에 적용돼.

작업 중 '이것도 고쳐야지' 하는 변경이 생길 때마다 원본 commit에 대해 git commit --fixup해. merge 전이나 review 뒤 git rebase -i --autosquash main을 실행하면 Git이 이력을 의도한 논리 단위로 조립해. 검토자는 깔끔한 version을 보고 main에는 과정의 잡음이 남지 않아.

Code

최근 commit amend·bash
# 파일 stage 잊음:
git add forgotten-test.js
git commit --amend --no-edit          # 마지막 commit 에 추가, 메시지 유지

# 메시지 고치기:
git commit --amend                    # editor 열림

# 합쳐서 (파일 추가 + 메시지 rewrite):
git add forgotten-test.js
git commit --amend                    # editor 가 옛 메시지로 열림
Fixup + autosquash workflow·bash
# Amend 하고 싶은 옛 commit 의 hash = abc1234.
# 보정 변경 stage:
git add src/auth.js
git commit --fixup abc1234
# "fixup! &lt;원본 제목&gt;" 제목인 commit 생성

# 나중에 merge / review 전:
git rebase -i --autosquash main
# Git 이 fixup commit 을 target 옆으로 재정렬 + squash 마킹.
# 저장 + 종료, autosquash 가 굴러.

# Autosquash 를 default 로 (한 번 설정):
git config --global rebase.autosquash true

External links

Exercise

연습용 branch에 message 오타나 빠진 파일 같은 작은 문제가 있는 commit 셋을 만들어. 가장 최근 것은 git commit --amend로 고치고 옛 commit 하나는 git commit --fixup <hash>로 보정해. git rebase -i --autosquash main을 실행해 Git이 순서를 어떻게 미리 배열하는지 관찰하고, 공개할 모양의 이력이 깔끔해졌는지 git log로 확인해.

Progress

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

댓글 0

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

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