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

섞인 working tree 쪼개기

~24 min · playbook, staging

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

섞인 working tree 를 깨끗한 commit 으로 쪼개기

이게 외울 playbook. 버그 고치려고 앉음. 3 시간 후 working tree 에 든 것: 실제 bug fix, 지나가다 고친 오타, 추가 후 제거 잊은 debug log, 관련 없는 config tweak, '여기 있는 김에' 명백해 보였던 helper refactor 한 개. 그걸 commit 하나로 push 하면 지저분 + history 오염. 일은 어떤 변경도 잃지 않고 결과를 깨끗하고 분리된 commit 으로 쪼개기.

절차. 1. git status -sb 로 앞에 뭐 있는지 확인. 2. git diff 로 모든 수정된 줄을 실제로 읽고 어떤 logical 그룹에 속하는지 결정 (bug fix vs 오타 vs refactor). 3. git stash push -k 로 unstaged 작업 옆에 두고 staged 부분 commit — 또는 stash 건너뛰고 바로 git add -p, 첫 관심사에 속하는 hunk 만 골라. 4. 집중된 메시지로 git commit. 5. 다음 관심사 반복: git add -p, commit. 6. Working tree 깨끗해지면 git log --oneline -p -n 5 돌려 결과 읽어 — commit 3-4 개가 각자 일관된 한 이야기 해야 함.

쪼개는 도중 뭔가 잘못되면 — 잘못된 hunk 를 우발적으로 stage 하고 commit 했어 — 옵션 있어. git reset --soft HEAD~1 이 commit undo + 변경은 staged 유지. 거기서 특정 파일에 git restore --staged --worktree 로 상태 reset + 다시 시작. 폐기하거나 push 하기 전엔 파괴적 일 안 일어나.

이 상황 막는 규율: 어떤 변경 만들지 명확한 한 줄 없이 '변경 만들기' 자리에 앉지 마. '비어 있는 검색 버그 고치는 중' 이 좋은 의도. '코드 작업할 거야' 가 섞인 tree 로 끝나는 방법. 부수적인 게 일어나야 하면 — refactor, 오타 — TODO list 에 적고 나중 별도 의도된 commit 으로 처리. 규율이 나중에 쪼개기보다 싸.

Code

쪼개기 루틴 — 복사 가능·bash
# 1. 둘러보기:
git status -sb
git diff

# 2. 첫 관심사의 hunk 만 stage:
git add -p src/search.js src/api.ts
# ('y/n/s/e' 로 accept, reject, split, edit)

# 3. Staged 된 거 sanity check:
git diff --staged

# 4. 집중된 메시지로 commit:
git commit -m "fix(search): handle empty result array in /api/search"

# 5. 다음 관심사 계속:
git add -p docs/api.md
git commit -m "docs(api): clarify /search response shape"

# 6. 마지막 통과 — 남은 양호한 거 commit:
git status -sb
너무 많이 commit 했을 때 회복·bash
# 마지막 commit 이 오타 + refactor 를 같은 commit 에 같이 넣은 거
# 방금 깨달음:
git reset --soft HEAD~1          # commit undo, 변경 staged 유지

# 이제 refactor hunk 만 선택적 unstage:
git restore --staged -p src/helper.js

# Fix 만 다시 commit:
git commit -m "fix(search): handle empty array"

# Refactor 별도로 stage + commit:
git add -p src/helper.js
git commit -m "refactor(helper): extract result-formatter"

External links

Exercise

Scratch repo 에 일부러 상황 구성: 한 편집 세션에서 진짜 버그 ('주' 변경) 고치고, 다른 곳에 관련 없는 debug log 추가, 주석 tweak. 이제 쪼개. git add -p 로 bug fix 만 stage + commit. Unstage + debug log 제거 다시 stage, commit. 그 다음 주석, commit. git log --oneline -p -n 3 으로 마무리, 깨끗한 commit 셋 확인. 실제 workflow 에서 섞인 tree 가장 자주 만드는 순간 적어.

Progress

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

댓글 0

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

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