git squash - ์ฌ๋ฌ๊ฐ์ ์ปค๋ฐ๋ก๊ทธ๋ฅผ ํ๋๋ก ๋ฌถ๊ธฐ
git squash - ์ฌ๋ฌ๊ฐ์ ์ปค๋ฐ๋ก๊ทธ๋ฅผ ํ๋๋ก ๋ฌถ๊ธฐ ๊ด๋ จ
์ ํํ ์ด์ผ๊ธฐํด์ git squash ๋ผ๋ ๋ช ๋ น์ด๋ ์์ต๋๋ค. interactive rebase๋ฅผ ํ๋๋ฐ ํ์ํ ๋ช ๋ น์ด ์ค ํ๋์ง์.
๋๋๋ก ์๋์ฒ๋ผ ํ๋์ ์์ ์ ์ฌ๋ฌ๋ฒ์ ๊ฑธ์ณ์ ์ปค๋ฐ์ ํ ๋๊ฐ ์์ต๋๋ค.
git log --pretty=oneline
#
# d442427eae836f15e94f5df0445c70081df79a3e Task 3/3
# 26395437be53e4e6e68f83aa98560ef93838aaa0 Task 2/3
# 7c6535580a038e9dcfaa72a98e04848812da9aee Task 1/3
# 2260a88777c247c31170ff6074d95569ac557afb Initial commit
์ฌ๊ธฐ์ Task 1/3~3/3 ์ ํ๋์ commit์ผ๋ก ๋ฌถ์ด๋ฒ๋ฆฌ๊ณ ์ถ์ ๊ฒฝ์ฐ๊ฐ ๋ง์ฃ .
์ด๋ด๋ ์ฌ์ฉํ๋๊ฒ์ด interactive rebase ์ ๋๋ค.
git rebase -i HEAD~3
(์ต๊ทผ 3๊ฐ์ ์ปค๋ฐ์ interactive rebase ํ๋ค๋ ๋ป์ ๋๋ค)
ํ๊ฒฝ์ ๋ฐ๋ผ ๋ค๋ฅด๊ฒ ์ง๋ง ๋ณดํต์ vi์๋ํฐ๊ฐ ๋จ๋ฉด์ ๋ค์๊ณผ ๊ฐ์ ๋ฉ์ธ์ง๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
pick 7c65355 Task 1/3
pick 2639543 Task 2/3
pick d442427 Task 3/3
# Rebase 2260a88..d442427 onto 2260a88
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
์์ ์ธ์ค์ ๋ค์๊ณผ ๊ฐ์ด ๋ฐ๊พธ์ด ์ค ํ ์ ์ฅ(:wq)๋ฅผ ๋๋ฅด๋ฉด
pick 7c65355 Task 1/3
squash 2639543 Task 2/3
squash d442427 Task 3/3
๋ค๋ฅธ vi์ฐฝ์ด ๋จ๋ฉด์ ์ปค๋ฐ ๋ฉ์ธ์ง๋ฅผ rewrite ํ ์ ์์ต๋๋ค.
pick 7c65355 Task 1/3
Rebasing (3/3)
# This is a combination of 3 commits.
# The first commit's message is:
Task 1/3
# This is the 2nd commit message:
Task 2/3
# This is the 3rd commit message:
Task 3/3
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# rebase in progress; onto 2260a88
# You are currently editing a commit while rebasing branch 'master' on '2260a88'.
#
# Changes to be committed:
# modified: README.md
#
๊ทธ๋ฆฌ๊ณ ๋ค์ ํ์ธํ๋ฉด ์ด๋ ๊ฒ ๋ฉ๋๋ค
git log --pretty=oneline
#
# 9833ca676c5a24361c1cc36fb173746328dfac3a Task 1/3 ~ 3/3
# 2260a88777c247c31170ff6074d95569ac557afb Initial commit
์ฐธ๊ณ
๊ฐ๋ฅํ๋ฉด ์ด๋ฏธ pushํ์ง ์์ ์์ ๋ง squash ํ๋๊ฒ์ ์ถ์ฒํฉ๋๋ค. push์ pull ์์ ์ด ์ด์ง ๋ฒ๊ฑฐ๋ก์ ์ง๋๋ค
git push -f
/ git fetch &&; git merge --squash