Bibi's DevLog ๐Ÿค“๐ŸŽ

[Git] ์ปค๋ฐ‹๋ฉ”์‹œ์ง€ ์ˆ˜์ •ํ•˜๋Š” ๋ฒ• ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Git & GIthub ๊นƒ๊ณผ ๊นƒํ—ˆ๋ธŒ

[Git] ์ปค๋ฐ‹๋ฉ”์‹œ์ง€ ์ˆ˜์ •ํ•˜๋Š” ๋ฒ•

๋น„๋น„ bibi 2021. 2. 16. 18:11

๊นƒ ์ปค๋ฐ‹๋ฉ”์‹œ์ง€ ์ˆ˜์ •ํ•˜๊ธฐ

์ถœ์ฒ˜ : ๊นƒ ์ปค๋ฐ‹๋ฉ”์‹œ์ง€ ์ˆ˜์ •. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค๐Ÿ™‡โ€โ™€๏ธ

1.์•„์ง ์ปค๋ฐ‹์ด ๋กœ์ปฌ์ €์žฅ์†Œ์— ์žˆ์„ ๋•Œ

๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ์ปค๋ฐ‹์€ ํ–ˆ์ง€๋งŒ, push๋Š” ์•„์ง ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ

  • ๊ฐ€์žฅ ์ตœ๊ทผ์˜ ์ปค๋ฐ‹ ์ˆ˜์ •ํ•˜๊ธฐ
    git commit --amend

  • ๋” ์˜ค๋ž˜๋œ ์ปค๋ฐ‹ ์ˆ˜์ •ํ•˜๊ธฐ, ๋˜๋Š” ํ•œ ๋ฒˆ์— ์—ฌ๋Ÿฌ ์ปค๋ฐ‹ ์ˆ˜์ •ํ•˜๊ธฐ

    • git log๋กœ ์ปค๋ฐ‹๋‚ด์—ญ์„ ๋ณด๋ฉฐ ์–ด๋–ค ์ปค๋ฐ‹์„ ์ˆ˜์ •ํ• ์ง€ ํ™•์ธํ•œ๋‹ค.

    • git rebase -i HEAD~์ˆซ์ž
      : ํ˜„์žฌ ๋ธŒ๋žœ์น˜์—์„œ ๊ฐ€์žฅ ์ตœ๊ทผ์˜ ์ปค๋ฐ‹ ์ˆซ์ž๊ฐœ๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

    • vim์ด ์—ด๋ฆฌ๊ณ  ์ตœ๊ทผ ์ปค๋ฐ‹๋“ค์ด ์•„๋ž˜์™€ ๊ฐ™์ด ๋‚˜ํƒ€๋‚œ๋‹ค.

      pick e499d89 Delete CNAME
      pick 0c39034 Better README
      pick f7fde4a Change the commit message but push the same commit.
      
      # Rebase 9fdb3bd..f7fde4a onto 9fdb3bd
      #
      # 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
    • ์ˆ˜์ •ํ•˜๊ณ  ์‹ถ์€ ์ปค๋ฐ‹์˜ pick์ด๋ผ๋Š” ๋ฌธ๊ตฌ๋ฅผ reword๋กœ ๋ฐ”๊พธ๊ณ  vim์„ ์ €์žฅ ๋ฐ ์ข…๋ฃŒํ•œ๋‹ค.

    • ์ปค๋ฐ‹์„ ์ˆ˜์ •ํ•˜๋Š” ์ฐฝ์ด ๋„์›Œ์ง€๋ฉด, ์ปค๋ฐ‹ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•˜๊ณ  vim์„ ์ €์žฅ ๋ฐ ์ข…๋ฃŒํ•œ๋‹ค.

2.์ปค๋ฐ‹์„ pushํ•ด ์›๊ฒฉ ์ €์žฅ์†Œ์— ์˜ฌ๋ฆฐ ์ƒํ™ฉ์ผ ๋•Œ

force๋ฅผ ํ†ตํ•ด ์ˆ˜์ •๋œ ์ปค๋ฐ‹์„ ๊ฐ•์ œ๋กœ pushํ•ด์ฃผ์–ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด๋‹ค.

ํ•˜์ง€๋งŒ force pushing์€ ๊นƒํ—ˆ๋ธŒ ๊ณต์‹ ๋ฌธ์„œ์—์„œ๋„ ์‚ฌ์šฉ์„ ์ง€์–‘ํ•˜๋Š” ๋ช…๋ น์–ด์ด๋‹ค.
(์ด์ „์— push๋œ ์ปค๋ฐ‹ ๋กœ๊ทธ๋ฅผ ๊ฐ–๊ณ  ์žˆ๋˜ ๋‹ค๋ฅธ ํŒ€์›๋“ค์€ ๋กœ๊ทธ๋ฅผ ์ˆ˜๋™์œผ๋กœ ์ˆ˜์ •ํ•ด์ค˜์•ผ ํ•˜๋Š” ์ƒํ™ฉ ๋ฐœ์ƒ)

  • ๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ 1.๋ฐฉ๋ฒ•์œผ๋กœ ์ˆ˜์ •ํ•œ ํ›„,
    git push --force ๋ธŒ๋žœ์น˜์ด๋ฆ„ ์ปค๋งจ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.