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

Interactive rebase: commit editor

~26 min · rebase, interactive

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

Interactive rebase 는 commit editor

git rebase -i <base><base> 와 현재 HEAD 사이 모든 commit 을 한 줄씩 보여주는 editor 를 열어. 줄을 편집해 Git 에 지시: 이 commit 유지, 저거 drop, 둘 reorder, 이거 squash, 저거 message edit, 여기 멈추고 amend 시켜줘. 저장 + 종료하면 Git 이 스크립트대로 commit 을 replay. 결과: 같은 (또는 편집했으면 다른) 내용에 도달하는 다른 모양의 history.

각 줄 앞 동사가 지시. pick 은 commit 그대로. reword 는 변경 유지 + 메시지 rewrite. edit 는 그 commit 에서 rebase 멈추고 임의 변경으로 git commit --amend 가능, 그 다음 git rebase --continue. squash 는 이전 commit 에 fold + 메시지 결합. fixup 은 squash 인데 fixup commit 메시지 폐기. drop 은 commit 완전 삭제. 줄 재배열 = commit 재배열, 줄 삭제 = drop.

가장 유용한 패턴: git rebase -i main 으로 merge 전 feature branch 정리 — WIP 수정을 parent commit 에 squash, 실험적 우회 drop, 모호한 메시지 reword. Commit 10 개를 3 logical unit 으로 재구성. 몇 달 된 commit 의 지금 부끄러운 log 줄 제거: git rebase -i <hash>~1, target 을 edit 으로, 고치고, git rebase --continue.

안전 사실 둘. Rebase 는 history rewrite. Commit hash 가 바뀜. 그 commit 이 push 됐고 남이 썼으면 조율 문제. Rebase 는 reversible. Push 전엔 git reset --hard ORIG_HEAD 가 rebase 전으로 rewind. Push 후에도 reflog 가 pre-rebase tip 을 90일 보유. Interactive rebase 중 실수는 loud (Git 이 conflict 에 멈춤) + recoverable (reflog) — 더 안전한 'powerful' Git 연산 중 하나.

Code

전형적 interactive rebase 스크립트·text
# git rebase -i main 이 editor 에 이런 거 보여줘:

pick    abc1234 Add OAuth2 GitHub login
fixup   def5678 fix config typo
reword  9876543 docs: add OAuth setup notes
edit    fedcba0 refactor: extract token storage
drop    1234abc experiment: log every request
pick    aabbcc1 Add logout button

# 동사:
#   pick    - 그대로
#   reword  - 변경 유지, 메시지 rewrite
#   edit    - 여기 멈추고 amend 가능
#   squash  - 이전 commit 에 fold, 메시지 결합
#   fixup   - 이전에 fold, 이 메시지 폐기
#   drop    - 이 commit 삭제
Interactive rebase 중간 흐름·bash
git rebase -i main
# 스크립트 편집, 저장, 종료.
# Git 이 replay 시작. "edit" 마킹한 게 있으면:

# Git 이 edit commit 에서 멈춤. 변경:
git add src/auth.js
git commit --amend
git rebase --continue

# Pick / squash 에 conflict 나면:
# (파일 해결 후)
git add resolved-file
git rebase --continue

# 통째로 빠지기, pre-rebase 상태 복원:
git rebase --abort

External links

Exercise

Commit 5 개 이상인 scratch branch 에서 git rebase -i HEAD~5. 스크립트에서 동사 셋 연습: 한 commit 에 reword, 작은 commit 을 이전 거에 fold 하는 fixup, rebase 중간 amend 용 edit. Edit 단계는 git rebase --continue 로 통과. git log 로 결과가 스크립트 모양인지 확인.

Progress

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

댓글 0

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

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