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

amend, fixup, autosquash

~22 min · amend, fixup

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

Publish 전 다듬기 — amend, fixup, autosquash

실전 코딩은 지저분해. Feature commit, 주석 오타 발견, 테스트 하나 업데이트 잊은 거 깨달음, docstring 손볼 거 기억. 그 네 commit 그대로 push 하면 noisy 해. 프로의 답: push 전에 local history 정리해서 main 에 올라가는 게 한 관심사 = 한 일관된 이야기로 읽히게. 이걸 하는 명령 셋: --amend, --fixup, --autosquash.

git commit --amend 는 가장 최근 commit 을 '이전 변경 + 지금 staged 인 거' 합친 새 commit 으로 교체. 원본 commit 의 hash 는 사라지고 새 commit 이 그 자리. 흔한 '파일 add 잊음' 또는 '메시지가 X 였어야' 케이스에 사용. Amend 가 메시지용 editor 열어, --no-edit 는 기존 메시지 그대로 재사용.

git commit --fixup <hash> 는 '나중에 commit <hash> 안으로 fold 돼야 함' 으로 마킹된 새 commit 만들어. Push 가능한 일반 commit 인데 'delayed amend' 라는 metadata 가 붙어. 짝꿍 git rebase -i --autosquash 가 그 마커를 읽고 각 fixup commit 을 target 에 squash 하도록 interactive rebase 를 배열 — 수동 재정렬 없음, 메시지 rewrite 없음. git config --global rebase.autosquash true 박으면 모든 interactive rebase 에서 자동.

이걸 굴리는 흐름: 작업 중 'oh and also' 변경마다 원본 commit 에 대한 git commit --fixup. 자유롭게 push. Merge 전이나 review 후 git rebase -i --autosquash main 하면 Git 이 정리된 history 를 조립. PR 의 pre-review noisy commit 들이 의도한 logical unit 으로 합쳐져. Reviewer 는 깨끗한 버전 보고, main 은 noise 안 봐.

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

Scratch branch 에 의도적 작은 문제 (메시지 오타, 파일 빠짐 등) 가진 commit 셋 만들어. 최근 거 git commit --amend 로 수정. 옛 거 하나는 git commit --fixup <hash> 로 보정. git rebase -i --autosquash main 돌리고 Git 이 rebase 를 어떻게 미리 배열하는지 관찰. Published-shape history 가 정리된 버전인지 git log 로 확인.

Progress

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

댓글 0

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

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