Git ๋ค์ ์ง์ ์ฌ์ฉ
์ด ์์ ์์๋ exec
๋ฅผ ์ ์ธํ๊ณ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ git rebase
๋ช
๋ น์ ๋ค๋ฃน๋๋ค.
ํฐ๋ฏธ๋์ git rebase --interactive HEAD~7
๋ฅผ ์
๋ ฅํ์ฌ ๋ค์ ์ง์ ์ ์์ํฉ๋๋ค. ์ฆ๊ฒจ ์ฐพ๋ ํ
์คํธ ํธ์ง๊ธฐ์ ๋ค์ ์ค์ด ํ์๋ฉ๋๋ค.
pick 1fc6c95 Patch A
pick 6b2481b Patch B
pick dd1475d something I want to split
pick c619268 A fix for Patch B
pick fa39187 something to add to patch A
pick 4ca2acc i cant' typ goods
pick 7b36971 something to move before patch B
์ด ์์ ์์๋ ๋ค์์ ์ฌ์ฉํฉ๋๋ค.
squash
๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ฏ ๋ฒ์งธ ์ปค๋ฐ(fa39187
)์"Patch A"
์ปค๋ฐ(1fc6c95
)์ ์ค์ฟผ์ํฉ๋๋ค.- ๋ง์ง๋ง ์ปค๋ฐ(
7b36971
)์"Patch B"
์ปค๋ฐ(6b2481b
) ์๋ก ์ด๋ํ๊ณpick
์ผ๋ก ์ ์งํฉ๋๋ค. "A fix for Patch B"
์ปค๋ฐ(c619268
)์"Patch B"
์ปค๋ฐ(6b2481b
)์ ๋ณํฉํ๊ณ ,fixup
์ ์ฌ์ฉํ์ฌ ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ๋ฌด์ํฉ๋๋ค.edit
์ ์ฌ์ฉํ์ฌ ์ธ ๋ฒ์งธ ์ปค๋ฐ(dd1475d
)์ ๋ ๊ฐ์ ๋ ์์ ์ปค๋ฐ์ผ๋ก ๋ถํ ํฉ๋๋ค.reword
๋ฅผ ์ฌ์ฉํ์ฌ ์ฒ ์๊ฐ ํ๋ฆฐ ์ปค๋ฐ(4ca2acc
)์ ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ์์ ํฉ๋๋ค.
ํด์ฐ! ํ ์ผ์ด ๋ง์ ๊ฒ์ฒ๋ผ ๋ค๋ฆฌ์ง๋ง ํ ๋ฒ์ ํ ๋จ๊ณ์ฉ ์ํํ๋ฉด ์ฝ๊ฒ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
์์ํ๋ ค๋ฉด ํ์ผ์ ๋ช ๋ น์ ๋ค์๊ณผ ๊ฐ์ด ์์ ํด์ผ ํฉ๋๋ค.
pick 1fc6c95 Patch A
squash fa39187 something to add to patch A
pick 7b36971 something to move before patch B
pick 6b2481b Patch B
fixup c619268 A fix for Patch B
edit dd1475d something I want to split
reword 4ca2acc i cant' typ goods
๊ฐ ์ค์ ๋ช
๋ น์ pick
์์ ๊ด์ฌ์ด ์๋ ๋ช
๋ น์ผ๋ก ๋ณ๊ฒฝํ์ต๋๋ค.
์ด์ ํธ์ง๊ธฐ๋ฅผ ์ ์ฅํ๊ณ ๋ซ์ต๋๋ค. ๊ทธ๋ฌ๋ฉด ๋ํํ ๋ค์ ์ง์ ์ด ์์๋ฉ๋๋ค.
Git์ ์๋ฌด๊ฒ๋ ์ํํ ํ์๊ฐ ์์ผ๋ฏ๋ก ์ฒซ ๋ฒ์งธ ๋ค์ ์ง์ ๋ช
๋ น pick 1fc6c95
๋ฅผ ๊ฑด๋๋๋๋ค. ๋ค์ ๋ช
๋ น squash fa39187
๋ก ์ด๋ํฉ๋๋ค. ์ด ์์
์๋ ์
๋ ฅ์ด ํ์ํ๋ฏ๋ก Git์์ ํ
์คํธ ํธ์ง๊ธฐ๊ฐ ๋ค์ ์ด๋ฆฝ๋๋ค. ์ด๋ฆฌ๋ ํ์ผ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
# This is a combination of two commits.
# The first commit's message is:
Patch A
# This is the 2nd commit message:
something to add to patch A
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: a
#
์ด ํ์ผ์ Git์ด ๋ค์๊ณผ ๊ฐ์ด ๋งํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค. โ์ง๊ธ ์ด squash
๋ก ํ๋ ค๋ ๊ฒ ๋ฐ๋ก ์ด๊ฒ์ด์์.โ ์ฒซ ๋ฒ์งธ ์ปค๋ฐ์ ๋ฉ์์ง("Patch A"
) ๋ฐ ๋ ๋ฒ์งธ ์ปค๋ฐ์ ๋ฉ์์ง("something to add to patch A"
)๋ฅผ ๋์ดํฉ๋๋ค. ์ด๋ฌํ ์ปค๋ฐ ๋ฉ์์ง์ ๋ง์กฑํ๋ฉด ํ์ผ์ ์ ์ฅํ๊ณ ํธ์ง๊ธฐ๋ฅผ ๋ซ์ ์ ์์ต๋๋ค. ๋ง์กฑํ์ง ์์ผ๋ฉด ๊ฐ๋จํ๊ฒ ํ
์คํธ๋ฅผ ๋ณ๊ฒฝํ์ฌ ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
ํธ์ง๊ธฐ๊ฐ ๋ซํ๋ฉด ๋ค์ ์ง์ ์ด ๊ณ์๋ฉ๋๋ค.
pick 1fc6c95 Patch A
squash fa39187 something to add to patch A
pick 7b36971 something to move before patch B
pick 6b2481b Patch B
fixup c619268 A fix for Patch B
edit dd1475d something I want to split
reword 4ca2acc i cant' typ goods
Git์ ๋ pick
๋ช
๋ น(pick 7b36971
๋ฐ pick 6b2481b
)์ ์ฒ๋ฆฌํฉ๋๋ค. ์ํธ ์์ฉ์ด ํ์ํ์ง ์์ผ๋ฏ๋ก ๋ํ fixup
๋ช
๋ น(fixup c619268
)์ ์ฒ๋ฆฌํฉ๋๋ค. fixup
์ c619268
์ ๋ณ๊ฒฝ ๋ด์ฉ์ ๊ทธ ์ด์ ์ ์ปค๋ฐ์ธ 6b2481b
์ ๋ณํฉํฉ๋๋ค. ๋ ๋ณ๊ฒฝ ๋ด์ฉ ๋ชจ๋ ๋์ผํ ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ํฌํจํ๊ฒ ๋ฉ๋๋ค("Patch B"
).
Git์ edit dd1475d
์์
์ ๋๋ฌํ๋ฉด ๋ฉ์ถ ํ ํฐ๋ฏธ๋์ ๋ค์ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
์ด ์์ ์์ ํ๋ก์ ํธ์ ํ์ผ์ ํธ์งํ์ฌ ์ถ๊ฐ๋ก ๋ด์ฉ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ๋ณ๊ฒฝํ ๋๋ง๋ค ์ ์ปค๋ฐ์ ์ํํด์ผ ํ๋ฉฐ, git commit --amend
๋ช
๋ น์ ์
๋ ฅํ์ฌ ์ํํ ์ ์์ต๋๋ค. ๋ชจ๋ ๋ณ๊ฒฝ ์์
์ ๋ง์ณค์ผ๋ฉด git rebase --continue
๋ฅผ ์คํํ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ฉด Git์ด reword 4ca2acc
๋ช
๋ น์ ๋๋ฌํฉ๋๋ค. ํ
์คํธ ํธ์ง๊ธฐ๊ฐ ํ ๋ฒ ๋ ์ด๋ฆฌ๊ณ ๋ค์ ์ ๋ณด๊ฐ ํ์๋ฉ๋๋ค.
i cant' typ goods
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Not currently on any branch.
# Changes to be committed:
# (use "git reset HEAD^1 <file>..." to unstage)
#
# modified: a
#
์ด์ ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก Git์ ํธ์งํ ์ปค๋ฐ ๋ฉ์์ง๋ฅผ ํ์ํฉ๋๋ค. ํ
์คํธ๋ฅผ ๋ณ๊ฒฝํ๊ณ ("i cant' typ goods"
), ํ์ผ์ ์ ์ฅํ๊ณ , ํธ์ง๊ธฐ๋ฅผ ๋ซ์ ์ ์์ต๋๋ค. ๋ค์ ์ง์ ์ด ์๋ฃ๋๊ณ ํฐ๋ฏธ๋๋ก ๋์๊ฐ๋๋ค.
๋ค์ ์ง์ ๋ ์ฝ๋๋ฅผ GitHub์ ํธ์
Git ๊ธฐ๋ก์ ๋ณ๊ฒฝํ์ผ๋ฏ๋ก ์ผ๋ฐ์ ์ธ git push origin
์ ์๋ํ์ง ์๊ฒ ๋ฉ๋๋ค. ์ต์ ๋ณ๊ฒฝ ๋ด์ฉ์ โ๊ฐ์ ํธ์โํ์ฌ ๋ช
๋ น์ ์์ ํด์ผ ํฉ๋๋ค.
# Don't override changes
$ git push origin main --force-with-lease
# Override changes
$ git push origin main --force
๊ฒฝ๊ณ
๊ฐ์ ํธ์๋ ๋ถ๊ธฐ์ ๋ํ ์ปค๋ฐ์ ๊ธฐ๋ก ์ํ์ค๋ฅผ ๋ณ๊ฒฝํ๊ธฐ ๋๋ฌธ์ ์ฌ๊ฐํ ์ํฅ์ ๋ฏธ์นฉ๋๋ค. ํนํ ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ฌ๋ฌ ์ฌ๋์ด ์ก์ธ์คํ๋ ๊ฒฝ์ฐ ์ฃผ์ํด์ ์ฌ์ฉํด์ผ ํฉ๋๋ค.