๋ฐ˜์‘ํ˜•

ํŠน์ • ๋ธŒ๋žœ์น˜์—์„œ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜๊ณ  git checkout ๋ช…๋ น์–ด๋กœ ์ž ์‹œ ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜๋กœ ์ด๋™ํ•˜๋ ค๊ณ  ํ•˜๋ฉด ์•„๋ž˜ ๋ฉ”์‹œ์ง€๊ฐ€ ๋‚˜์˜จ๋‹ค.

Please commit your changes or stash them before you switch branches.

 

๋ณ€๊ฒฝํ•œ ๋‚ด์šฉ์„ commitํ•˜๊ฑฐ๋‚˜ stash ํ•ด์•ผ๋งŒ ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๋ฉ”์‹œ์ง€๋‹ค. ์•„์ง ์™„๋ฃŒํ•˜์ง€ ์•Š์€ ์ž‘์—…์„ commitํ•˜๊ธฐ ๊ป„๋„๋Ÿฌ์šธ ๋•Œ stash ๋ช…๋ น์–ด๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งˆ๋ฌด๋ฆฌํ•˜์ง€ ์•Š์€ ์ž‘์—…์„ stash ์Šคํƒ์— ์ž„์‹œ ์ €์žฅํ•œ ํ›„ ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Stash ๋ช…๋ น์–ด


stashํ–ˆ๋˜ ๋ธŒ๋žœ์น˜๊ฐ€ ์•„๋‹ˆ์–ด๋„(๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜์—์„œ๋„) stash์— ์ €์žฅํ•œ ๋‚ด์šฉ์„ ๋ณต์›(์ ์šฉ)ํ•  ์ˆ˜ ์žˆ๋‹ค

 

stash ์Šคํƒ์— ์ €์žฅ

# ํ˜„์žฌ ์ƒํƒœ ์ž„์‹œ ์ €์žฅ โญ๏ธ
git stash

 

stash ๋ชฉ๋ก ํ™•์ธ

# ์ €์žฅํ•œ stash ๋ชฉ๋ก ํ™•์ธ
git stash list

 

์ €์žฅํ•œ stash ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

# ๊ฐ€์žฅ ์ตœ๊ทผ ์ €์žฅํ•œ stash ๋ถˆ๋Ÿฌ์˜ค๊ธฐ(์ ์šฉ)
git stash apply

# stash@{2} ์ด๋ฆ„์˜ stash ๋ถˆ๋Ÿฌ์˜ค๊ธฐ(์ ์šฉ)
git stash apply stash@{2}

# Staged ํ–ˆ๋˜ ์ƒํƒœ๊นŒ์ง€ ๋ณต์›ํ•˜์—ฌ stash ๋ถˆ๋Ÿฌ์˜ค๊ธฐ(์ ์šฉ)
git stash apply --index

# stash ์ ์šฉ(๋ถˆ๋Ÿฌ์˜ค๊ธฐ)์™€ ๋™์‹œ์— stash ์ œ๊ฑฐ โญ๏ธ
git stash pop

 

stash ์ œ๊ฑฐ

# stash ์ œ๊ฑฐ
git stash drop

# stash@{2} ์ด๋ฆ„์˜ stash ์ œ๊ฑฐ
git stash drop stash@{2}

 

stash ์ ์šฉ ์ด์ „ ์ƒํƒœ๋กœ ๋ณต๊ตฌ (์‹ค์ˆ˜๋กœ stash ํ–ˆ์„ ๋•Œ ์‚ฌ์šฉ)

# ๊ฐ€์žฅ ์ตœ๊ทผ stash๋ฅผ ์ ์šฉํ–ˆ๋˜ ๋‚ด์šฉ์„ ์ด์ „ ์ƒํƒœ๋กœ ๋ณต๊ตฌ
git stash show -p | git apply -R

# stash@{2} ์ด๋ฆ„์˜ stash๋กœ ์ ์šฉํ–ˆ๋˜ ๋‚ด์šฉ์„ ์ด์ „ ์ƒํƒœ๋กœ ๋ณต๊ตฌ
git stash show -p stash@{2} | git apply -R

 

Alias ๋ช…๋ น์–ด ๋“ฑ๋ก


์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ์›ํ•˜๋Š” ์ „์—ญ ํ˜น์€ ์ง€์—ญ Alias๋กœ ๋“ฑ๋กํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

# git stash show -p | git apply -R ๋ช…๋ น์–ด๋ฅผ git stash-unapply ์ „์—ญ Alias๋กœ ๋“ฑ๋ก
git config --global alias.stash-unapply '!git stash show -p | git apply -R'

# ๋“ฑ๋กํ•œ ์ „์—ญ Alias ๋ชฉ๋ก ๋ณด๊ธฐ
git config --global --get-regexp alias
# alias.stash-unapply !git stash show -p | git apply -R

# ๋“ฑ๋กํ•œ ์ „์—ญ Alias ์‚ญ์ œ
git config --global --unset alias.stash-unapply

 

์ฐธ๊ณ 


 


๊ธ€ ์ˆ˜์ •์‚ฌํ•ญ์€ ๋…ธ์…˜ ํŽ˜์ด์ง€์— ๊ฐ€์žฅ ๋น ๋ฅด๊ฒŒ ๋ฐ˜์˜๋ฉ๋‹ˆ๋‹ค. ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”
๋ฐ˜์‘ํ˜•