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

stash: 임시 선반이지 창고가 아님

~18 min · stash, wip

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

Stash는 잠깐 쓰는 선반이지 창고가 아니야

git stash는 commit하지 않은 staged와 unstaged 작업을 나중을 위한 snapshot stack에 올리고 작업 트리를 비워. feature 작업 도중 main의 긴급 bug를 고쳐야 하지만 아직 commit할 수 없을 때 알맞아. stash하고, switch해 고치고, 돌아와 pop하면 돼. 잠깐의 방해가 반쯤 끝낸 작업을 오염시키지 않지.

git stash push -m "WIP feature/x"는 작업을 저장하고 작업 트리를 정리해. git stash list는 선반의 항목을 보여주고, git stash pop은 가장 최근 항목을 복원한 뒤 stack에서 없애. git stash apply는 항목을 남긴 채 적용해서 같은 stash를 여러 branch에 쓸 때 유용해. git stash drop <ref>은 특정 항목을, git stash clear는 전부 지워.

날마다 쓸 만한 flag는 둘이야. -u(--include-untracked)는 Git이 아직 추적하지 않는 새 파일도 담아. 빼먹으면 untracked file은 작업 트리에 남아 branch switch 때 놓칠 수 있어. -k(--keep-index)는 unstaged 변경만 stash하고 staged 변경은 남겨. staged 부분을 commit하고 나머지는 잠깐 치울 때 좋아.

Stash는 선반이지 창고가 아니야. branch를 가로질러 살고 오래 남을 수 있지만 로컬에만 있고 잊기 쉬워. 석 달 전 아무도 기억하지 못하는 stash는 죽은 짐이고 codebase가 변한 뒤에는 conflict도 풀기 어려워. 몇 시간짜리 방해에는 stash를 쓰고, 며칠 뒤 돌아올 작업은 WIP branch에 commit해. 세션을 시작할 때 git stash list를 보면 commit으로 옮기거나 버릴 항목을 찾을 수 있어.

Code

방해 처리용 stash 동작·bash
# Feature 중에 긴급 버그 방해:
git stash push -m "WIP: feature/profile-page"

# Working tree 깨끗. Switch 해서 고치기:
git switch hotfix/login-bug
# ... 고치고, commit, push ...

# Feature 작업으로 복귀:
git switch feature/profile-page
git stash pop

# 선반에 뭐 있는지 list:
git stash list
# stash@{0}: On feature/profile-page: WIP: feature/profile-page
유용한 flag·bash
# Untracked 파일 포함 (아주 흔한 요청):
git stash push -u -m "WIP with new files"

# Staged 부분 유지, unstaged 만 stash:
git stash push -k -m "shelf the unstaged side"

# 제거 없이 apply (여러 branch 에 선택적으로):
git stash apply stash@{0}

# 특정 stash drop:
git stash drop stash@{2}

# 모든 stash 삭제 (위험 — 복구 불가):
git stash clear

External links

Exercise

staged와 unstaged file 여러 개, untracked file 하나를 만들어. -u와 제대로 된 message로 stash한 뒤 branch를 바꿔 다른 commit을 하나 만들어. 돌아와 git stash list를 보고 git stash pop해. untracked file까지 모두 돌아왔는지 확인해. 두 번째 stash를 만든 뒤 일부러 git stash drop하고 pop과 apply의 차이를 적어봐.

Progress

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

댓글 0

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

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