TIL 022 | git stash

This Is Empty.ยท2021๋…„ 9์›” 29์ผ
0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
22/23
post-thumbnail
post-custom-banner

stash ?

stash๋Š” ์šฐ๋ฆฌ๋ง๋กœ (์•ˆ์ „ํ•œ ๊ณณ์—) ๋„ฃ์–ด๋‘๋‹ค[์ˆจ๊ธฐ๋‹ค] ๋ผ๋Š” ๋œป์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

git stash --help๋กœ ํ™•์ธํ•ด ๋ณด๋ฉด
Use git stash when you want to record the current state of the working ๋ผ๊ณ  ์„ค๋ช…ํ•˜๊ณ  ์žˆ๋‹ค.

์šฐ๋ฆฌ๋Š” ํ•œ ๋ธŒ๋žœ์น˜์—์„œ ์ž‘์—…์„ ํ•˜๋˜ ์ค‘ ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜๋กœ ์˜ฎ๊ธฐ๊ณ  ์‹ถ์„๋•Œ๊ฐ€ ์žˆ์ง€๋งŒ, git์€ commit์„ ํ•˜์ง€ ์•Š์œผ๋ฉด ๋ธŒ๋žœ์น˜๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋‹ค๊ณ  ๊ฒฝ๊ณ ํ•œ๋‹ค.

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

git stash๋ž€ ?

git stash๋Š” ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๊ธฐ๋กํ•˜๊ณ  HEAD commit๊ณผ ์ผ์น˜ํ•˜๋„๋ก ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊นจ๋—ํ•˜๊ฒŒ ๋ณ€๊ฒฝ์‹œ์ผœ ์ค€๋‹ค. ์ฆ‰, ์•„์ง ๋งˆ๋ฌด๋ฆฌํ•˜์ง€ ์•Š์€ ์ž‘์—…์„ ์Šคํƒ์— ์ž ์‹œ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๋ช…๋ น์–ด์ด๋‹ค.

USE

  1. stash ์ƒ์„ฑํ•˜๊ธฐ
    ๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋กœ ์ƒˆ๋กœ์šด stash๋ฅผ ์ƒ์„ฑํ•ด ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ž„์‹œ๋กœ ์ €์žฅํ•œ๋‹ค.
git stash

  1. stash ๋ชฉ๋ก ํ™•์ธํ•˜๊ธฐ
git stash list

  1. stash ์ ์šฉํ•˜๊ธฐ(ํ–ˆ๋˜ ์ž‘์—…์„ ๋‹ค์‹œ ๊ฐ€์ ธ์˜ค๊ธฐ)
git stash apply ([stash ์ด๋ฆ„])

ํ˜„์žฌ ์ž‘์—… ๋ธŒ๋žœ์น˜์— stash์— ์ €์žฅํ–ˆ๋˜ ํ•ญ๋ชฉ์„ ์ ์šฉํ•œ๋‹ค.

  1. stash ์ œ๊ฑฐํ•˜๊ธฐ
git stash drop ([stash ์ด๋ฆ„])

apply๋Š” ๋‹จ์ˆœํžˆ stash๋ฅผ ์ ์šฉํ•˜๋Š” ๊ฒƒ์œผ๋กœ ํ•ด๋‹น stash๋Š” list๋กœ ํ™•์ธ์‹œ ์—ฌ์ „ํžˆ ๋‚จ์•„์žˆ๋‹ค. drop์œผ๋กœ stash๋ฅผ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ๋‹ค.

๋งŒ์•ฝ ์ ์šฉ๊ณผ ๋™์‹œ์— stash๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด

git stash pop

์„ ์‚ฌ์šฉํ•œ๋‹ค.

  1. ์ถ”์ ๋˜์ง€ ์•Š์€ ํŒŒ์ผ stash
    git stash๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์žˆ๋Š” ํŒŒ์ผ๋งŒ stashํ•œ๋‹ค. .gitignore์— ์žˆ๋Š” ํŒŒ์ผ์ด๋‚˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์—†๋Š” ํŒŒ์ผ๋„ stashํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
git stash -u

git pull ๊นœ๋นกํ–ˆ์„๋•Œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋˜ git stash ์ •๋ฆฌ๐Ÿ˜…

์ฐธ๊ณ 
git | git-stash
How Git Stash Can Help You Juggle Multiple Branches

profile
Convinced myself, I seek not to convince.
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€