Git

Git ๋ฒ„์ „ ์‚ญ์ œ, ๋ฒ„์ „ ๋˜๋Œ๋ฆฌ๊ธฐ

๋…ธ๋ฃจ๋ฃฝ 2020. 8. 9. 20:27

 

๋ฒ„์ „ ์‚ญ์ œ - git reset

ํ˜„์žฌ ์ƒํƒœ

Message 2๋กœ ๋ฆฌ์…‹ํ•œ๋‹ค.

== Message 2๋ฅผ ์‚ญ์ œํ•œ๋‹ค๋Š” ๊ฒƒ X!!! Message 2 ๋ฒ„์ „์ด ๋˜๊ฒ ๋‹ค๋Š” ๋œป!!! (ํ—ท๊ฐˆ๋ฆฌ๋‹ˆ ์ฃผ์˜!)

 

git reset --hard ์ปค๋ฐ‹ ID

์ด๋ฏธ ๋‹ค๋ฅธ ์‚ฌ๋žŒ๊ณผ ํ˜‘์—… ์ค‘์ธ ๊ฒฝ์šฐ์—๋Š” reset ํ•˜๋ฉด ์•ˆ ๋จ. ํ”„๋กœ๊ทธ๋žจ์ด ์—‰ํ‚ค๊ฒŒ ๋œ๋‹ค.

 

๋ฒ„์ „ ๋˜๋Œ๋ฆฌ๊ธฐ - git revert

ํ˜„์žฌ ์ƒํƒœ

โ€ป์ฃผ์˜โ€ป

reset์—์„œ๋Š” R3๋กœ ๊ฐ€๊ธฐ ์œ„ํ•ด git reset R3์˜ ์ปค๋ฐ‹ ID

revert์—์„œ๋Š” R3๋กœ ๊ฐ€๊ธฐ์œ„ํ•ด git revert R4์˜ ์ปค๋ฐ‹ ID

 

git revert R4์˜ ์ปค๋ฐ‹ ID

ctrl + x ํ›„ y

๊ธฐ์กด์˜ R4๋Š” ๋‚ด๋ฒ„๋ ค ๋‘๊ณ , ์ด ์ปค๋ฐ‹์˜ ๋ณ€ํ™”๋งŒ ์ทจ์†Œํ•œ ๊ฒƒ. == R3 ์ƒํƒœ

 

git log -p

R4๊ฐ€ revert ๋˜์—ˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

(+) ๋งŒ์•ฝ Message 1์„ revert ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด? Message 2๋ฅผ revert ํ•ด์•ผ ํ•˜๋‚˜?

revert R4 -> R3 -> Message 2 ์ด๋ ‡๊ฒŒ ์—ญ์ˆœ์œผ๋กœ revert ํ•ด์•ผ ํ•œ๋‹ค. ์•ˆ ๊ทธ๋Ÿฌ๋ฉด ์ถฉ๋Œ ์ผ์–ด๋‚จ!!

 

์ผ๋ถ€ ํŒŒ์ผ์€ ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ์›์น˜ ์•Š๋Š” ๊ฒฝ์šฐ - .gitignore ์‚ฌ์šฉ

.gitignore๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ๊ฑฐ๊ธฐ์— ํŒŒ์ผ ์ด๋ฆ„์„ ์ž…๋ ฅ.

 

 

๋” ์ •๋ฆฌ ์ž˜๋˜์–ด์žˆ๋Š” ๊ณณ์„ ์ฐพ์•˜๋‹ค!

https://m.blog.naver.com/PostView.nhn?blogId=minimalist06&logNo=221652212303&proxyReferer=https:%2F%2Fblog.naver.com%2Fminimalist06%2F221652212303

 

(์ƒํ™œ์ฝ”๋”ฉ) GIT2 - CLI ๋ฒ„์ „๊ด€๋ฆฌ - 7~10. ๋ฒ„์ „ ์‹œ์ ๋ณ€๊ฒฝ(checkout), ์‚ญ์ œ(reset), ๋˜๋Œ๋ฆฌ๊ธฐ(revert) (๋)

git log ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ–ˆ์„ ๋•Œ ์ € master๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€? - ํ˜„์žฌ๋กœ์„œ๋Š” master๋Š” ์ตœ์‹ ๋ฒ„์ „์ด๋‹ค. ์ •๋„๋กœ๋งŒ ์•Œ์•„...

blog.naver.com