Skip to content

Latest commit

ย 

History

History
28 lines (20 loc) ยท 1.75 KB

moving-a-commit-to-a-different-branch.ko.md

File metadata and controls

28 lines (20 loc) ยท 1.75 KB

์ปค๋ฐ‹์„ ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜๋กœ ์˜ฎ๊ธฐ๊ธฐ

What if you commit a change, and then realize that you committed to a different branch? How can you change that? This is what this tutorial covers. ๋งŒ์ผ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ–ˆ๋Š”๋ฐ ์ „ํ˜€ ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜์— ์ปค๋ฐ‹ํ•œ ์‚ฌ์‹ค์„ ์•Œ์•˜๋‹ค๋ฉด ์–ด๋–ป๊ฒŒํ• ๊นŒ์š”? ์ด๊ฑธ ์–ด๋–ป๊ฒŒ ๋ฐ”๋กœ์žก์„ ์ˆ˜ ์žˆ์„๊นŒ์š”? ๋ฐ”๋กœ ์ด ์žฅ์—์„œ ๋‹ค๋ฃฐ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค.

๊ฐ€์žฅ ์ตœ๊ทผ ์ปค๋ฐ‹๋“ค์„ ๊ธฐ์กด์— ์žˆ๋Š” ๋ธŒ๋žœ์น˜๋กœ ์ด๋™์‹œํ‚ค๊ธฐ

์‚ฌ์šฉ์˜ˆ:

git reset HEAD~ --soft - ๋งˆ์ง€๋ง‰ ์ปค๋ฐ‹์„ ๋˜๋Œ๋ฆฝ๋‹ˆ๋‹ค. ๋ฌผ๋ก  ์ˆ˜์ •ํ•œ ๋‚ด์šฉ์€ ๊ทธ๋Œ€๋กœ ๋‚จ์•„์žˆ์Šต๋‹ˆ๋‹ค.
git stash - ํ˜„์žฌ๊นŒ์ง€ ์ˆ˜์ •ํ•œ ๋ชจ๋“  ์ž‘์—…๋‚ด์šฉ๋“ค์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

git checkout name-of-the-correct-branch - ์‹ค์ œ ๋ฐ˜์˜ํ•˜๊ณ ์žํ•˜๋Š” ๋ธŒ๋žœ์น˜๋ฅผ ์ฒดํฌ์•„์›ƒํ•ฉ๋‹ˆ๋‹ค. git stash pop - ๋งˆ์ง€๋ง‰์œผ๋กœ ์ €์žฅํ•œ(stash) ๋ณ€๊ฒฝ๋‚ด์—ญ๋“ค์„ ํ˜„์žฌ ๋ธŒ๋žœ์น˜์— ๋ฐ˜์˜ํ•˜๊ณ  ์ €์žฅํ•œ ๋‚ด์—ญ์—์„œ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.
git add . - ๋˜๋Š” ์ปค๋ฐ‹์— ๋ฐ˜์˜ํ•  ๋ณ€๊ฒฝ๋‚ด์—ญ๋“ค์„ ๊ฐœ๋ณ„์ ์œผ๋กœ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
git commit -m "your message here" - ์ €์žฅํ•˜๊ณ  ๋ณ€๊ฒฝ๋‚ด์—ญ์„ ์ปค๋ฐ‹ํ•ฉ๋‹ˆ๋‹ค.

์ž ์ด์ œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์˜ฌ๋ฐ”๋ฅธ ๋ธŒ๋žœ์น˜์— ๋ฐ˜์˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๊ฐ€์žฅ ์ตœ๊ทผ ์ปค๋ฐ‹๋“ค์„ ์‹ ๊ทœ ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์ด๋™์‹œํ‚ค๊ธฐ

์‚ฌ์šฉ์˜ˆ:
git branch newbranch - ์‹ ๊ทœ ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋ชจ๋“  ์ปค๋ฐ‹๋“ค์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
git reset --hard HEAD~# - master ๋ธŒ๋žœ์น˜์˜ #๋ฒˆ์งธ ์ปค๋ฐ‹์„ ๋˜๋Œ๋ฆฝ๋‹ˆ๋‹ค. ๋˜๋Œ๋ฆฐ ์ปค๋ฐ‹๋“ค์€ master์—์„œ ์™„์ „ํžˆ ์‚ญ์ œ๋˜๋ฏ€๋กœ ์ฃผ์˜ํ•˜์„ธ์š”.
git checkout newbranch - ์ƒ์„ฑํ•œ ๋ธŒ๋žœ์น˜๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  ์ปค๋ฐ‹๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ์„๊ฒ๋‹ˆ๋‹ค.

์ฃผ์˜: ์ปค๋ฐ‹ํ•˜์ง€ ์•Š์€ ๋ณ€๊ฒฝ์‚ฌํ•ญ๋“ค์€ ์‚ฌ๋ผ์ง‘๋‹ˆ๋‹ค.