ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ” ํ˜„ ์ƒํ™ฉ

ํ”„๋กœ์ ํŠธ ์ง„ํ–‰ ๊ณผ์ •

 

ํ”„๋กœ์ ํŠธ๋ฅผ ํ•˜๋ฉด์„œ ์Šคํ”„๋ฆฐํŠธ๋ฅผ ๋‘ ๊ฐœ๋กœ ๋‚˜๋ˆ„์—ˆ๋‹ค. ๊ฐ ์Šคํ”„๋ฆฐํŠธ๋ฅผ ๋ธŒ๋žœ์น˜๋กœ ๋งŒ๋“ค์—ˆ๋‹ค.

์ฒซ ์Šคํ”„๋ฆฐํŠธ ๋‹จ์œ„๋Š” ๋ธŒ๋žœ์น˜ ์ด๋ฆ„์œผ๋กœ sprint1 ์„ ์‚ฌ์šฉํ–ˆ๋‹ค. sprint1 ์„ source ๋ธŒ๋žœ์น˜๋กœ ๊ฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ํ•  ๋•Œ๋งˆ๋‹ค 1๊ฐœ ๋ธŒ๋žœ์น˜์”ฉ ๋งŒ๋“ค์—ˆ๊ณ , ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ๋งˆ์น  ๋•Œ๋งˆ๋‹ค sprint1 ์œผ๋กœ๋งŒ ๋ณ‘ํ•ฉ์„ ํ•˜๊ณ  main ์€ ๋†”๋‘์—ˆ๋‹ค.

sprint1 ์˜ ๋ชจ๋“  ์ž‘์—…์„ ๋งˆ์นœ ํ›„ main ๋ธŒ๋žœ์น˜์— ๋ณ‘ํ•ฉ์„ ํ•  ์ƒ๊ฐ์ด์—ˆ๋‹ค.

 

๋ฌธ์ œ ๋ฐœ์ƒ

์Šคํ”„๋ฆฐํŠธ๊ฐ€ ๋๋‚˜๊ธฐ ์ „๊นŒ์ง€ ๋ชจ๋“  ๊ธฐ๋Šฅ ๋‹จ์œ„์— ๋Œ€ํ•œ ๋ธŒ๋žœ์น˜๋Š” sprint1 ์—๋งŒ ๋ณ‘ํ•ฉ, ์ฆ‰ merge ๊ฐ€ ๋˜์–ด์•ผ ํ–ˆ๋‹ค.

๊ทผ๋ฐ ๋ฌด์Šจ ์ƒ๊ฐ์ด์—ˆ๋Š”์ง€, ์‹ค์ˆ˜๋กœ Target branch ๋ฅผ ๋ฐ”๊พธ์–ด์ฃผ์ง€ ์•Š๊ณ  main ์— ๊ธฐ๋Šฅ ํ•œ ๊ฐœ๋ฅผ merge ํ•˜๊ณ  ๋ง์•˜๋‹ค.

Source branch -> Target branch ๋กœ merge ๊ฐ€ ์ง„ํ–‰๋œ๋‹ค. sprint1->main merge ๋ฅผ ์š”์ฒญํ•˜๋Š” ๋ชจ์Šต.

 

์ดํ›„ main ์— ์Šคํ”„๋ฆฐํŠธ ๋‹จ์œ„๊ฐ€ ๋๋‚˜๊ธฐ ์ „๊นŒ์ง€๋Š” ํ”์ ์ด ๋‚จ์ง€ ์•Š์•˜์œผ๋ฉด ์ข‹๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ ๋•Œ๋ฌธ์— ๊ธ‰ํžˆ revert ๋ฅผ ๋ˆŒ๋Ÿฌ๋ฒ„๋ ธ๋‹ค.

 

18๋ฒˆ์งธ ์ด์Šˆ์— ๋Œ€ํ•ด main ์œผ๋กœ ๋ณ‘ํ•ฉํ•œ ํ›„ ๊ธ‰ํžˆ revert ํ•œ ํ”์ 

revert ์‚ฌ์šฉ์„ ํ”์ ๋„ ์—†์ด merge ํ–ˆ๋˜ ํŒŒ์ผ๋“ค์ด ์‚ฌ๋ผ์ง€๊ณ  ์•„๋ฌด ๋ฌธ์ œ ์—†์–ด์ง€๋Š” ํƒ€์ž„๋จธ์‹ ์„ ์ด์šฉํ•˜๋Š” ๊ฒƒ์ด๋ผ๊ณ  ์ฐฉ๊ฐํ–ˆ๋‹ค.

 

ํ•˜์ง€๋งŒ, revert ๋Š” ๋ฐ˜๋“œ์‹œ ํ”์ ์„ ๋‚จ๊ธด๋‹ค.

 

merge ํ›„ revert ํ•œ ๊ธฐ๋ก์ด main ๋ธŒ๋žœ์น˜์˜ ๋””๋ ‰ํ† ๋ฆฌ์™€ ํŒŒ์ผ์— ์ปค๋ฐ‹ ๊ธฐ๋ก์œผ๋กœ ๋‚จ์•˜๋‹ค.

์‹œ๊ฐ„์ด ํ˜๋Ÿฌ, ์–ด๋Š๋ง ์ฒซ ์Šคํ”„๋ฆฐํŠธ ๋‹จ์œ„๊ฐ€ ๋๋‚˜๋Š” ์‹œ์ ์ด ๋˜์–ด์„œ sprint1 -> main ์˜ merge request ๋ฅผ ์ง„ํ–‰ํ–ˆ๊ณ ,

main branch ๋Š” ์ฒ˜์Œ sprint1 ์—์„œ ์ถœ๋ฐœํ–ˆ๋˜ main ๊ณผ ๋‹ฌ๋ผ์ ธ ์žˆ์—ˆ์œผ๋ฏ€๋กœ, merge conflict ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค!

 

merge ํ•  ์ˆ˜ ์—†๋‹จ๋‹ค.

 

๋ช‡ ๊ฐœ์˜ ์ž์ž˜ํ•œ ํŒŒ์ผ๋“ค์ด main branch ์— ์ถ”๊ฐ€๋˜์—ˆ์œผ๋ฉด ๋‹จ์ˆœํžˆ ํŒŒ์ผ์„ ์ง€์šฐ๊ณ  merge ๋ฅผ ๋‹ค์‹œ ์ง„ํ–‰ํ•˜๋ฉด ๋˜์—ˆ๊ฒ ์ง€๋งŒ, revert ๊ธฐ๋ก ๋งŒ ์ฒ˜์Œ sprint1 ๋ธŒ๋žœ์น˜๋ฅผ ์ƒ์„ฑํ–ˆ์„ ๋•Œ์˜ main ๊ณผ ๋‹ค๋ฅธ ์ƒํ™ฉ์—์„œ๋Š” ๊ณผ์—ฐ ์–ด๋–ป๊ฒŒ merge conflict ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์„๊นŒ?

 

๐Ÿ”‘ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

 

์•„๋ž˜ Stack Overflow ํŽ˜์ด์ง€์—์„œ ๋‚ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด์ค„ ๊ฒƒ ๊ฐ™์€ ์งˆ์˜์‘๋‹ต์„ ์ฐพ์•˜๋‹ค.

 

https://stackoverflow.com/questions/1078146/re-doing-a-reverted-merge-in-git

 

Re-doing a reverted merge in Git

I have run into a bit of a problem here: I had a problem-specific branch 28s in Git, that I merged in the general develop branch. Turns out I had done it too fast, so I used git-revert to undo the ...

stackoverflow.com

 

์š”์•ฝํ•˜์ž๋ฉด, merge ๋ฅผ revert ํ•˜๋Š” ์ž‘์—…์€ ๊ธฐ์ˆ ์ ์œผ๋กœ ์ฆ‰, ํŒŒ์ผ์˜ ๋ณ€๋™์— ๊ด€๋ จํ•ด์„  ์ „ํ˜€ ๋ฌธ์ œ๊ฐ€ ์—†์ง€๋งŒ, ์›Œํฌํ”Œ๋กœ์šฐ, ์ฆ‰ ์ž‘์—…์˜ ํ๋ฆ„์˜ ๊ด€์ ์—์„œ๋Š” ์›ฌ๋งŒํ•˜๋ฉด ํ•ด์„  ์•ˆ๋˜๋Š” ์ผ ์ด๋ผ๊ณ  ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๊ฒฐ๊ตญ ์ด๋ฏธ merge ๋ฅผ revert ํ–ˆ๋‹ค๋ฉด, ์–ด๋–ค ์ด์œ ๋กœ๋“  ๋‹ค์‹œ ๊ฐ™์€ merge ๋ฅผ ์‹คํ–‰ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์— ๋†“์ธ๋‹ค๋ฉด (๋‚˜์˜ ๊ฒฝ์šฐ main ์— sprint1 ์„ merge ํ•˜๊ธฐ ์œ„ํ•ด์„œ) revert ๋ฅผ revert ํ•˜๋Š” ๋ฐฉ๋ฒ•๋ฐ–์—๋Š” ์—†๋‹ค ๊ณ  ๋งํ•œ๋‹ค. (๊ทธ๋ž˜์„œ revert ๋ฅผ revert ๋Š” ์–ด๋–ป๊ฒŒ ํ•˜๋Š”๊ฑด๋ฐ...)

๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜ ๋งํฌ๋ฅผ ์ฒจ๋ถ€ํ•ด revert ๋ฅผ revert ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•˜๊ณ  ์žˆ๋‹ค:

 

https://mirrors.edge.kernel.org/pub/software/scm/git/docs/howto/revert-a-faulty-merge.txt

 

๋‚ด์šฉ์„ ์‚ดํŽด๋ณด๋ฉด, ์ค‘๊ฐ„์— ์•„๋ž˜์™€ ๊ฐ™์€ ์„ค๋ช…์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค. merge commit ์„ revert ํ•˜๋ฉด regular commit (์ผ๋ฐ˜์ ์ธ ์ปค๋ฐ‹) ์˜ revert ์™€๋Š” ๋‹ค๋ฅด๊ฒŒ data ๋งŒ merge ์ „์œผ๋กœ ์›์ƒ๋ณต๊ท€๋˜๊ณ  history ์—๋Š” ์•„๋ฌด๋Ÿฐ ๋ณ€ํ™”๊ฐ€ ์—†๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์ฆ‰, ํ”์ ์ด ๋‚จ๋Š”๋‹ค.

Reverting a regular commit just effectively undoes what that commit did, and is fairly straightforward. But reverting a merge commit also undoes the _data_ that the commit changed, but it does absolutely nothing to the effects on _history_ that the merge had.

์ดํ›„ ๊ธ€์—์„œ๋Š” ๋‹ค์Œ ์ปค๋งจ๋“œ๋กœ merge ์˜ revert ์ž์ฒด๋ฅผ revert ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ด์•ผ๊ธฐํ•œ๋‹ค.

$ git revert <merge revert>

๋‚ด ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด, ์šฐ์„  ์ธํ…”๋ฆฌ์ œ์ด์—์„œ main ๋ธŒ๋žœ์น˜์˜ merge revert ๋‹น์‹œ์˜ ์ƒํƒœ๋ฅผ ๊ด€์ฐฐํ–ˆ๋‹ค.

๋ณด๋ผ์ƒ‰์œผ๋กœ ๋˜์–ด ์žˆ๋Š” main ๋ธŒ๋žœ์น˜์— ํ•œ ๋ธŒ๋žœ์น˜๊ฐ€ merge ๋˜์—ˆ๋‹ค๊ฐ€ revert ๋œ ๊ธฐ๋ก์ด ๋‚จ์€ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
๋งˆ์šฐ์Šค ์šฐํด๋ฆญ์„ ํ•˜๋‹ˆ revert commit ์ด ์žˆ์—ˆ๋‹ค.

revert commit ์„ ๋ˆŒ๋Ÿฌ๋ณด๋‹ˆ, ๊ทธ๋ž˜ํ”„ ๋ชจ์–‘์ด ๋ฐ”๋€Œ์—ˆ๊ธฐ๋Š” ํ–ˆ์ง€๋งŒ ์ง๊ด€์ ์œผ๋กœ ๋ธŒ๋žœ์น˜์˜ ๊ธฐ๋ก์ด ๋ฐ”๋€ ์—ฌ๋ถ€๋ฅผ ์•Œ ์ˆ˜ ์—†์–ด์„œ GitLab ์—์„œ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•ด ๋ณด๋‹ˆ๊นŒ ๊ฐ€๋Šฅํ–ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์ด ํ•˜๋ฉด ๋œ๋‹ค.

 

1. main ๋ธŒ๋žœ์น˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ Last commit ์˜ ๋ฌธ๊ตฌ๋ฅผ ๋ˆŒ๋Ÿฌ revert ํ•˜๊ณ  ์‹ถ์€ revert ์˜ commit ๊ธฐ๋ก์„ ํ™•์ธํ•œ๋‹ค.

2. ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ์— ๋ณด์ด๋Š” Options ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ Revert ์˜ต์…˜์„ ์„ ํƒํ•œ๋‹ค.

3. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฐฝ์ด ๋œจ๋Š”๋ฐ, merge request ๋ฅผ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด์„œ revert ์˜ revert ๋ฅผ ์ง„ํ–‰ํ•˜๊ณ  ์‹ถ์œผ๋ฉด ์ฒดํฌ๋ฐ•์Šค๋ฅผ ์ฒดํฌํ•œ๋‹ค.

๋‚˜๋Š” merge request ๊ฐ€ ์–ด๋–ป๊ฒŒ ์ƒ์„ฑ๋˜๋Š”์ง€ ๋ณด๊ณ  ์‹ถ์–ด์„œ ์ฒดํฌ๋ฐ•์Šค๋ฅผ ์ฒดํฌํ–ˆ๋‹ค.

4. revert commit ์ด ์„ฑ๊ณต์ ์œผ๋กœ revert ๋˜์—ˆ๋‹ค๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋œจ๋Š”๋ฐ, merge request ๋ฅผ ์ œ์ถœํ•˜๋ฉด revert ๋ฅผ revert ํ•œ ๋ณ€ํ™”๋ฅผ ๋ธŒ๋žœ์น˜์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์“ฐ์—ฌ์žˆ๋‹ค.

revert ๋ฅผ revert ํ•˜๋Š” merge request ์ด๋‹ค.

์—ฌ๊ธฐ์„œ ๊ณ ๋ฏผ์ด ์ƒ๊ฒผ๋‹ค. merge ๋ฅผ revert ํ•จ์œผ๋กœ์„œ revert ๊ธฐ๋ก์ด ๋‚จ์•„์„œ ์ด ๊ธฐ๋ก์„ revert ํ•˜๋ ค๊ณ  ํ•˜๋‹ˆ, ์ด๋ฒˆ์—๋Š” revert ๋ฅผ revert ํ•œ ๊ธฐ๋ก์ด ๋‚จ์„ ๊ฒƒ ๊ฐ™์•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์‹ค์ œ๋กœ ์ƒ์„ฑ๋˜์—ˆ๋‹ค๋Š” revert-b1ef1ff6 ๋ธŒ๋žœ์น˜๋ฅผ ํ™•์ธํ•ด๋ณด๋‹ˆ, revert ๋ฅผ revert ํ•œ ์ปค๋ฐ‹ ๊ธฐ๋ก๋“ค์ด ๋‚จ์•„์žˆ์—ˆ๋‹ค.

์‹ค์ˆ˜๋กœ merge ํ–ˆ์„ ๋•Œ์™€ ๊ฐ™์€ ํŒŒ์ผ๋“ค์ด ์žˆ๊ณ , ๋งˆ์ง€๋ง‰ ์ปค๋ฐ‹ ๋ฌธ๊ตฌ๋Š” revert ๋ฅผ revert ํ•œ๋‹ค๊ณ  ์“ฐ์—ฌ ์žˆ์—ˆ๋‹ค.

์šฐ์„  merge ๋ฅผ ํ•œ ํ›„ ์ • ์•ˆ๋˜๋ฉด main ์„ ์ง€์šฐ๊ณ  sprint1 ์„ main ๋ธŒ๋žœ์น˜๋กœ ๋งŒ๋“ค์–ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์— merge request ๋ฅผ ๋ณด๋ƒˆ๋‹ค. ๊ทธ๋Ÿฌ์ž main ์€ ์‹ค์ˆ˜๋กœ ๋ฌธ์ œ ๋ธŒ๋žœ์น˜ 18-postservice ๋ฅผ merge ํ–ˆ์„ ๋•Œ์™€ ๊ฐ™์€ ์ƒํ™ฉ์ด ๋˜์—ˆ๊ณ , ํ˜„์žฌ sprint1 ๋„ ๊ฐ™์€ ๋ฌธ์ œ ๋ธŒ๋žœ์น˜ 18-postservice ๋ฅผ sprint1 ์— merge ํ•œ ์ดํ›„๊นŒ์ง€๋Š” main ๊ณผ ๊ฐ™๊ณ  ์ค„๊ณง ๋ณ€ํ•œ ์ƒํ™ฉ์ด์—ˆ๊ธฐ ๋•Œ๋ฌธ์— sprint1 ์„ main ์— merge ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•ด์กŒ๋‹ค. ๊ฒฐ๋ก ์ ์œผ๋กœ sprint1 ์„ main ์— ์„ฑ๊ณต์ ์œผ๋กœ merge ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

merge request ๊ฐ€ merge conflict ์—†์ด ๋ฐ›์•„๋“ค์—ฌ์กŒ๋‹ค.

๐Ÿ“ƒ ๊ฒฐ๋ก 

merge ๋ฅผ revert ํ•œ ๊ธฐ๋ก์œผ๋กœ ์ธํ•ด ๋ธŒ๋žœ์น˜ A ์— ๋ณ€๋™์‚ฌํ•ญ์ด ์ƒ๊ฒจ ๋ธŒ๋žœ์น˜ A ์˜ merge revert ์ด์ „๋ถ€ํ„ฐ ๋ณ€ํ™”๋ฅผ ์Œ“์•„์˜ฌ๋ฆฐ ๋ธŒ๋žœ์น˜ B ์˜ ๋ธŒ๋žœ์น˜ A ๋กœ์˜ merge ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด, merge ๋ฅผ revert ํ•œ revert commit ์„ ํ•œ ๋ฒˆ ๋” revert ํ•˜์—ฌ merge ๋ฅผ revert ํ•œ ๊ธฐ๋ก์„ ์—†์• ๋Š” ๊ฒƒ์œผ๋กœ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๐Ÿ“ข ์ถœ์ฒ˜

https://itnext.io/git-revert-the-revert-88b1e66d71d4

 

Gitโ€Š—โ€ŠRevert The Revert.

TL;DR - if you think of “revert” as “undo”, then you’re going to always miss this part of reverts. Yes, it undoes the data, but no, it…

itnext.io

 

๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
๊ธ€ ๋ณด๊ด€ํ•จ