๋ฐ˜์‘ํ˜•

TL;DR


  • reset : ํ˜„์žฌ ๋ธŒ๋žœ์น˜๋ฅผ ์ง€์ •ํ•œ ์ปค๋ฐ‹์œผ๋กœ ์ด๋™. ๊ทธ ์ดํ›„์˜ ์ปค๋ฐ‹ ํžˆ์Šคํ† ๋ฆฌ๋Š” ์‚ญ์ œ
  • revert : ์ปค๋ฐ‹ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ทจ์†Œํ•˜๋Š” ์ƒˆ๋กœ์šด ์ปค๋ฐ‹ ์ƒ์„ฑ. ๊ธฐ์กด ์ปค๋ฐ‹ ํžˆ์Šคํ† ๋ฆฌ๋Š” ์œ ์ง€

 

HEAD ๋ฐฐ๊ฒฝ์ง€์‹


Git Branch ํ•™์Šต/์—ฐ์Šตํ•˜๊ธฐ ์ข‹์€ ์‚ฌ์ดํŠธ โ–ผ

 

Learn Git Branching

An interactive Git visualization tool to educate and challenge!

learngitbranching.js.org

 

  • HEAD๋Š” ํ˜„์žฌ ๋ธŒ๋žœ์น˜ ์ž‘์—… ํŠธ๋ฆฌ์˜ ๊ฐ€์žฅ ์ตœ๊ทผ ์ปค๋ฐ‹์„ ๊ฐ€๋ฆฌํ‚จ๋‹ค(ํ˜„์žฌ ์ž‘์—…์ค‘์ธ ์ปค๋ฐ‹).
  • HEAD๋ฅผ ๋ธŒ๋žœ์น˜ ๋Œ€์‹  ์ปค๋ฐ‹์— ๋ถ™์ด๋Š” ๊ฒƒ์„ HEAD ๋ถ„๋ฆฌ๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
  • ^(์บ๋Ÿฟ) ์—ฐ์‚ฐ์ž๋Š” ์ƒ๋Œ€์ฐธ์กฐ ๊ธฐ๋Šฅ์œผ๋กœ, ํ•œ ๋‹จ๊ณ„ ์œ„(๋ถ€๋ชจ) ์ปค๋ฐ‹์œผ๋กœ ์ด๋™ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
git checkout bugFix^ # bugFix ์ปค๋ฐ‹์˜ ๋ถ€๋ชจ๋กœ ์ด๋™(HEAD ๋ถ„๋ฆฌ)
git checkout HEAD^ # ํ˜„์žฌ ์ปค๋ฐ‹์˜ ๋ถ€๋ชจ๋กœ ์ด๋™(HEAD ๋ถ„๋ฆฌ)

 

  • ^^ ๋ฅผ ๋‘ ๋ฒˆ ์“ฐ๋ฉด “์กฐ๋ถ€๋ชจ(๋ถ€๋ชจ์˜ ๋ถ€๋ชจ)” ์ปค๋ฐ‹์œผ๋กœ ์ด๋™ํ•œ๋‹ค.
  • ์—ฌ๋Ÿฌ ์ปค๋ฐ‹ ์œ„๋กœ ์ด๋™ํ•  ๋• ~<num> ๋ฌผ๊ฒฐํ‘œ(ํ‹ธํŠธ) ์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•œ๋‹ค. ex) HEAD~3
  • ^, ~ ๊ฐ™์€ ์ƒ๋Œ€ ์ฐธ์กฐ๋Š” -f ์˜ต์…˜์„ ์ด์šฉํ•ด ๋ธŒ๋žœ์น˜๋ฅผ ํŠน์ • ์ปค๋ฐ‹์œผ๋กœ (๊ฐ•์ œ)์žฌ์ง€์ •ํ•  ๋•Œ ์œ ์šฉํ•˜๋‹ค.
git branch -f bugFix HEAD~3 # bugFix ๋ธŒ๋žœ์น˜๋ฅผ 3๋ฒˆ ๋’ค์˜ ์ปค๋ฐ‹์œผ๋กœ ์žฌ์ง€์ •

 

git reset


git reset์€ โžŠํ˜ผ์ž ์‚ฌ์šฉํ•˜๋Š” ๋ธŒ๋žœ์น˜๋‚˜ โž‹origin์— ์žˆ์ง€๋งŒ ์•„๋ฌด๋„ ์ด ๋ธŒ๋žœ์น˜๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ํ™•์‹ ์ด ์žˆ์„ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ๋‹ค๋ฅธ ์‚ฌ๋žŒ๊ณผ ํ•จ๊ป˜ ์ž‘์—…ํ•˜๋Š” ๋ธŒ๋žœ์น˜์—์„œ reset์„ ์‚ฌ์šฉํ•˜๋ฉด ํ—ฌ๊ฒŒ์ดํŠธ๊ฐ€ ์—ด๋ฆด ์ˆ˜๋„ ์žˆ๋‹ค.

 

์•„๋ž˜์ฒ˜๋Ÿผ ์ด 3๋ฒˆ์˜ ์ปค๋ฐ‹์„ ํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž.

// log.js
console.log('commit1'); // ์ฒซ๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit2'); // ๋‘๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit3'); // ์„ธ๋ฒˆ์งธ ์ปค๋ฐ‹
git log --oneline
# 74d1dc1 (HEAD -> master) commit 3
# 0057e3f commit 2
# fa3e214 commit 1

 

git reset --mixed HEAD^

  • ๋งˆ์ง€๋ง‰ commit ์ทจ์†Œ
  • ๋ณ€๊ฒฝ ๋‚ด์—ญ์€ unstaged ์ƒํƒœ๋กœ ๋‚จ์•„์žˆ์Œ
  • git reset HEAD^ ์™€ ๋™์ผ
git rest HEAD^ # commit 3์ด ์‚ญ์ œ๋จ
git log --oneline
# 0057e3f (HEAD -> master) commit 2
# fa3e214 commit 1

git status
# Changes not staged for commit:
# modified:   revert.js
# no changes added to commit (use "git add" and/or "git commit -a")
# commit 3์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์ด unstaged ์ƒํƒœ๋กœ ๋‚จ์•„ ์žˆ์Œ
// reset ํ›„์˜ log.js
console.log('commit1'); // ์ฒซ๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit2'); // ๋‘๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit3'); // ์„ธ๋ฒˆ์งธ ์ปค๋ฐ‹

 

git reset --soft HEAD^

  • ๋งˆ์ง€๋ง‰ commit ์ทจ์†Œ
  • ๋ณ€๊ฒฝ ๋‚ด์—ญ์€ staged ์ƒํƒœ๋กœ ๋‚จ์•„์žˆ์Œ
git reset --soft HEAD^ # commit 3์ด ์‚ญ์ œ๋จ
git log --oneline
# 0057e3f (HEAD -> master) commit 2
# fa3e214 commit 1

git status
# Changes to be committed:
# modified:  revert.js
# commit 3์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์ด staged ์ƒํƒœ๋กœ ๋‚จ์•„ ์žˆ์Œ
// reset ํ›„์˜ log.js
console.log('commit1'); // ์ฒซ๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit2'); // ๋‘๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit3'); // ์„ธ๋ฒˆ์งธ ์ปค๋ฐ‹

 

git reset --hard HEAD^

๐Ÿ’ก ์ปค๋ฐ‹์€ ๋ฌผ๋ก  ๋ณ€๊ฒฝ ๋‚ด์šฉ๋„ ๊ฐ™์ด ์‚ญ์ œ๋˜๋ฏ€๋กœ ์ฃผ์˜

 

  • ๋งˆ์ง€๋ง‰ commit ์ทจ์†Œ
  • ์ทจ์†Œํ•œ commit์˜ ๋ณ€๊ฒฝ ๋‚ด์—ญ๋„ ์‚ญ์ œ๋จ
git reset --hard HEAD^ # commit 3์ด ์‚ญ์ œ๋จ
git log --oneline
# 0057e3f (HEAD -> master) commit 2
# fa3e214 commit 1

git status
# nothing to commit, working tree clean
# commit 3์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ๋„ ์‚ญ์ œ๋ผ์„œ commit 2 ์ƒํƒœ๋กœ ๋Œ์•„๊ฐ
// reset ํ›„์˜ log.js
console.log('commit1'); // ์ฒซ๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit2'); // ๋‘๋ฒˆ์งธ ์ปค๋ฐ‹

 

git reset HEAD~n

  • ๋งˆ์ง€๋ง‰ n๊ฐœ์˜ commit ์ทจ์†Œ
  • ๋ณ€๊ฒฝ ๋‚ด์—ญ์€ unstaged ์ƒํƒœ๋กœ ๋‚จ์•„์žˆ์Œ — git reset --mixed HEAD^์™€ ๋™์ผ
git reset HEAD~2 # ๋งˆ์ง€๋ง‰ commit 2๊ฐœ ์‚ญ์ œ (commit 2, commit 3 ์‚ญ์ œ)
git log --oneline
# fa3e214 (HEAD -> master) commit 1

git status
# Changes not staged for commit:
# modified:   revert.js
# no changes added to commit (use "git add" and/or "git commit -a")
# commit 2 / commit 3์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์ด unstaged ์ƒํƒœ๋กœ ๋‚จ์•„ ์žˆ์Œ
// reset ํ›„์˜ log.js
console.log('commit1'); // ์ฒซ๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit2'); // ๋‘๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit3'); // ์„ธ๋ฒˆ์งธ ์ปค๋ฐ‹

 

git reset --option commitHash

์•„๋ž˜์ฒ˜๋Ÿผ commit hash๋ฅผ ์ง์ ‘ ์ž…๋ ฅํ•˜๋ฉด ํ•ด๋‹น commit์œผ๋กœ ๋Œ์•„๊ฐ€๊ณ , ๊ทธ ์ดํ›„์˜ commit์€ ๋ชจ๋‘ ์‚ญ์ œ๋œ๋‹ค.

git reset --mixed a232ba2
# a232ba2 ์ปค๋ฐ‹์œผ๋กœ ๋Œ์•„๊ฐ€๊ณ , ๊ทธ ์ดํ›„์— ํ–ˆ๋˜ ์ปค๋ฐ‹์€ ๋ชจ๋‘ ์‚ญ์ œ

 

  • git reset --mixed|--soft commitHash
    • ์ž…๋ ฅํ•œ commit์œผ๋กœ ๋Œ์•„๊ฐ€๊ณ , ๊ทธ ์ดํ›„์˜ commit์€ ๋ชจ๋‘ ์‚ญ์ œ๋จ
    • ๋งˆ์ง€๋ง‰ commit ๊นŒ์ง€์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์€ ๋ชจ๋‘ ๋‚จ์•„์žˆ์Œ
      • --mixed : unstaged ์ƒํƒœ
      • --soft : staged ์ƒํƒœ
  • git reset --hard commitHash
    • ์ž…๋ ฅํ•œ commit์œผ๋กœ ๋Œ์•„๊ฐ€๊ณ , ๊ทธ ์ดํ›„์˜ commit์€ ๋ชจ๋‘ ์‚ญ์ œ๋จ
    • ๋Œ์•„๊ฐ„ commit ์ดํ›„์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ๋„ ๋ชจ๋‘ ์‚ญ์ œ๋จ

 

git revert


๐Ÿ’ก ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— push ํ•œ ํ›„ ๋กœ์ปฌ์—์„œ reset์„ ์ด์šฉํ•ด commit์„ ์‚ญ์ œํ•œ ์ƒํƒœ์—์„  ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋กœ push ํ•  ์ˆ˜ ์—†๋‹ค. reset ์ด์ „ ์ƒํƒœ๋กœ ๋˜๋Œ๋ฆฌ๊ฑฐ๋‚˜ --force ์˜ต์…˜์œผ๋กœ ๋กœ์ปฌ commit ์ด๋ ฅ์„ ์›๊ฒฉ commit ์ด๋ ฅ์— ๋ฎ์–ด์จ์•ผ ํ•œ๋‹ค. ํ•˜์ง€๋งŒ ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ์ž‘์—…ํ•˜๋Š” ๋ธŒ๋žœ์น˜์—์„œ --force ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ฉด ํ—ฌ๊ฒŒ์ดํŠธ๊ฐ€ ์—ด๋ฆด ์ˆ˜๋„ ์žˆ์œผ๋‹ˆ ์ฃผ์˜ํ•œ๋‹ค. ํ˜‘์—…ํ•˜๋Š” ๋ธŒ๋žœ์น˜๋ผ๋ฉด reset์€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒŒ ์ข‹๋‹ค.

 

commit ์ด๋ ฅ์„ ์‚ญ์ œํ•˜๋Š” reset๊ณผ ๋‹ฌ๋ฆฌ revert๋Š” Revert “...” ํ˜•ํƒœ๋กœ ์ด๋ ฅ์ด ์ถ”๊ฐ€๋œ๋‹ค. ํŠนํžˆ ์ค‘๊ฐ„์— ์žˆ๋Š” ์ปค๋ฐ‹ ๋‚ด์šฉ๋งŒ ์‚ญ์ œํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์œ ์šฉํ•˜๋‹ค. ์ด๋ฏธ ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— pushํ•œ ์ƒํƒœ์ผ ๋•Œ๋„ revert๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. ์ปค๋ฐ‹ ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ์™œ ์‚ญ์ œํ–ˆ๋Š”์ง€์— ๋Œ€ํ•œ ์ด๋ ฅ์„ ๋‚จ๊ธธ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์œ ์ง€๋ณด์ˆ˜ ์ฐจ์›์—์„œ reset๋ณด๋‹ค ์ข‹๋‹ค.

 

์‚ฌ์šฉ ๋ฐฉ๋ฒ•

revert๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด...

  • ์ž…๋ ฅํ•œ commit์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ๋งŒ ์‚ญ์ œ — commit ์ด๋ ฅ์€ ๊ทธ๋Œ€๋กœ ๋‚จ์•„ ์žˆ์Œ
  • commit ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ์‚ญ์ œํ•œ ์ด๋ ฅ์ด Revert “...” commit์œผ๋กœ ๋‚จ์Œ
git revert commit2hash # commit 2 ๋ณ€๊ฒฝ ๋‚ด์šฉ ์‚ญ์ œ
git log --oneline
# 8aaf2a3 (HEAD -> master) Revert "commit 2" -> commit 2 ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ์‚ญ์ œํ•œ ์ด๋ ฅ์ด ๋‚จ์Œ
# 3991c6d commit 3
# 49ec5d0 commit 2 -> ํ•ด๋‹น ์ปค๋ฐ‹์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์ด ์‚ญ์ œ๋จ / ์ปค๋ฐ‹ ์ด๋ ฅ์€ ๋ณด์กด๋จ
# a0d48a6 commit 1

 

-n ์˜ต์…˜

Revert “...” ์ด๋ ฅ์„ ๋‚จ๊ธฐ๊ณ  ์‹ถ์ง€ ์•Š๋‹ค๋ฉด -n(ํ˜น์€ --no-commit) ์˜ต์…˜์„ ๋ถ™์ด๋ฉด ๋œ๋‹ค. revertํ•œ ๊ฒฐ๊ณผ์˜ stage ์ƒํƒœ๋งŒ ์œ ์ง€ํ•˜๊ณ  revert ์ด๋ ฅ์ด ๋‚จ์ง€ ์•Š๋Š”๋‹ค.

git revert -n commit2hash # commit 2 ๋ณ€๊ฒฝ ๋‚ด์šฉ ์‚ญ์ œ
git status # commit 2์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ์‚ญ์ œํ•œ ํ›„์˜ ๊ฒฐ๊ณผ๊ฐ€ staged๋œ ์ƒํƒœ
# You are currently reverting commit 24e6e6e(commit 2).
# Changes to be committed: modified: revert.js

git log --oneline
# 7c87c84 (HEAD -> master) commit 3
# 24e6e6e commit 2
# 717d3a8 commit 1

 

Fork GUI์—์„œ Commit the changes ์˜ต์…˜์— ์ฒดํฌํ•ด์ œํ•˜๊ณ  revertํ•˜๋Š”๊ฒƒ๊ณผ ๋™์ผํ•˜๋‹ค.

 

์—ฌ๋Ÿฌ ์ปค๋ฐ‹ revert

์•„๋ž˜์ฒ˜๋Ÿผ ์—ฌ๋Ÿฌ commit์„ revertํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

git revert commit2hash commit3hash # commit 2, commit 3 ๋ณ€๊ฒฝ๋‚ด์šฉ ์‚ญ์ œ
git log --oneline
# 5af042f (HEAD -> master) Revert "commit 3"
# 0e450b3 Revert "commit 2"
# 0d1d8ba commit 3
# 7f68fc8 commit 2
# 0b84063 commit 1

 

์ด๋ฏธ pushํ•œ commit์„ ์ทจ์†Œํ•ด์•ผ ๋œ๋‹ค๋ฉด?


๐Ÿ’ก ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ์ž‘์—…ํ•˜๋Š” ๋ธŒ๋žœ์น˜์—์„œ ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— pushํ•œ ํ›„ commit์„ ์ทจ์†Œํ•ด์•ผ ๋˜๋Š” ์ƒํ™ฉ์ด๋ผ๋ฉด revert๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์ •์‹ ๊ฑด๊ฐ•์— ์ข‹๋‹ค.

 

push ์˜ค๋ฅ˜ ์ƒํ™ฉ ์žฌํ˜„

โถ commit์„ 3๋ฒˆํ•˜๊ณ  ํ•˜๊ณ  ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— push

// log.js
console.log('commit1'); // ์ฒซ๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit2'); // ๋‘๋ฒˆ์งธ ์ปค๋ฐ‹
console.log('commit3'); // ์„ธ๋ฒˆ์งธ ์ปค๋ฐ‹

 

โท ๋กœ์ปฌ์—์„œ reset์„ ์‚ฌ์šฉํ•ด 3๋ฒˆ์งธ commit ์ทจ์†Œ (reset์— ์˜ต์…˜์ด ์—†์œผ๋ฏ€๋กœ reset --mixed ์™€ ๋™์ผ)

git reset HEAD^
git log --oneline
# 969e77a commit 2
# 321e8ab commit 1

 

โธ 4๋ฒˆ์งธ commit ํ›„ ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— pushํ•˜๋ ค๊ณ  ํ•˜๋ฉด ์•„๋ž˜ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ

# ! [rejected] master -> master (non-fast-forward)
# error: failed to push some refs to '...'

 

์›์ธ ๋ฐ ํ•ด๊ฒฐ

์œ„๋Š” ๋กœ์ปฌ commit์„ ์‚ญ์ œํ•œ ์ƒํƒœ์—์„œ, ์›๊ฒฉ์— ์žˆ๋Š” commit์„ ๋ฎ์–ด์“ฐ๋ ค๊ณ  ํ•ด์„œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ๋‹ค. ์ด๋• ์•„๋ž˜ 2๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ด “์–ต์ง€๋กœ” ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค(์ถ”์ฒœํ•˜์ง€ ์•Š๋Š” ๋ฐฉ๋ฒ•).

 

โถ ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ mergeํ•œ ํ›„ ๋‹ค์‹œ push ํ•˜๋Š” ๋ฐฉ๋ฒ• (reset ์ด์ „ ์ƒํƒœ๋กœ ๋˜๋Œ๋ฆฌ๋Š” ๊ฒƒ๊ณผ ๋™์ผ)

git pull origin master # ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ commit ์ด๋ ฅ์ด ๋กœ์ปฌ์— merge๋จ
git log --oneline
# 7941eb9 (HEAD -> master) Merge branch 'master' of ... -> merge commit
# d606c9b commit 4
# e56800b (origin/master) commit 3 -> ๋กœ์ปฌ์—์„  ์‚ญ์ œํ–ˆ์ง€๋งŒ ์›๊ฒฉ์—” ๋‚จ์•„์žˆ์œผ๋ฏ€๋กœ mergeํ•  ๋•Œ ๋™๊ธฐํ™”๋จ
# 969e77a commit 2
# 321e8ab commit 1

 

--hard ์˜ต์…˜์œผ๋กœ commit์„ ์‚ญ์ œํ–ˆ๋‹ค๋ฉด ๋ณ€๊ฒฝ ๋‚ด์šฉ๊ณผ ์ปค๋ฐ‹ ์ด๋ ฅ์ด ๋ชจ๋‘ ์—†์œผ๋ฏ€๋กœ merge ์—†์ด ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์žˆ๋Š” commit 3 ๋ณ€๊ฒฝ ๋‚ด์šฉ๊ณผ commit ์ด๋ ฅ์ด ๋กœ์ปฌ์— ๋™๊ธฐํ™”๋œ๋‹ค.

 

--soft ํ˜น์€ --mixed ์˜ต์…˜์œผ๋กœ commit์„ ์‚ญ์ œํ–ˆ๋‹ค๋ฉด commit 3์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์€ ๋กœ์ปฌ์— ๋‚จ์•„์žˆ์ง€๋งŒ commit ์ด๋ ฅ์ด ์—†์œผ๋ฏ€๋กœ ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์™€ commit ์ด๋ ฅ์„ ๋งž์ถ”๊ธฐ ์œ„ํ•ด mergeํ•ด์•ผ ํ•œ๋‹ค.

 

๋งŒ์•ฝ reset ํ›„ ๋กœ์ปฌ ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ ์‚ญ์ œํ•˜๊ณ  pullํ•˜๋ฉด merge ์—†์ด commit 3 ๋ณ€๊ฒฝ ๋‚ด์šฉ๊ณผ commit ์ด๋ ฅ์ด ๋กœ์ปฌ์— ๋™๊ธฐํ™”๋œ๋‹ค.

 

โท โ›”๏ธ -f(ํ˜น์€ --force) ์˜ต์…˜์œผ๋กœ ๋กœ์ปฌ commit ์ด๋ ฅ์„ ์›๊ฒฉ commit ์ด๋ ฅ์— ๋ฎ์–ด์“ฐ๊ธฐ ํ•˜๋Š” ๋ฐฉ๋ฒ•

git push origin master -f
git log --oneline # ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ commit ์ด๋ ฅ์ด ์•„๋ž˜์™€ ๋™์ผํ•ด์ง(๊ฐ•์ œ๋กœ ๋ฎ์–ด์”€)
# d606c9b commit 4
# 969e77a commit 2
# 321e8ab commit 1

 

๊ฒฐ๋ก 

์—ฌ๋Ÿฌ ๋ช…์ด ์ž‘์—…ํ•˜๋Š” ๋ธŒ๋žœ์น˜์—์„  -f ์˜ต์…˜์œผ๋กœ ์›๊ฒฉ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ commit ์ด๋ ฅ์„ ๋ฎ์–ด์“ฐ๋Š” ๊ฒƒ์€ ๊ธˆ์ง€ํ•ด์•ผ ๋  ํ–‰์œ„ ์ค‘ ํ•˜๋‚˜๋‹ค. ํ—ฌ๊ฒŒ์ดํŠธ๊ฐ€ ์—ด๋ฆด ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๊ฒฐ๋ก , ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ์ž‘์—…ํ•˜๋Š” ๋ธŒ๋žœ์น˜์—์„œ ์ด๋ฏธ pushํ–ˆ๋˜ commit์„ ์ทจ์†Œํ•ด์•ผ ๋˜๋Š” ์ƒํ™ฉ์ด๋ผ๋ฉด revert๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

 

๋ ˆํผ๋Ÿฐ์Šค


 


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