Git

Git ๋ฒ„์ „ ์ฐจ์ด์  ๋น„๊ต, ๋ฒ„์ „๊ณผ ๋ฒ„์ „์„ ๋„˜๋‚˜๋“ค๊ธฐ

๋…ธ๋ฃจ๋ฃฝ 2020. 8. 9. 12:47

๋ฒ„์ „ ๊ฐ„์˜ ์ฐจ์ด์  ๋น„๊ต

hello1.txt ์ˆ˜์ •

 

git diff

์ฐจ์ด์ ์„ ํ•œ๋ˆˆ์— ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

git reset --hard

์ž‘์—…์„ ์ด์ „ ๋ฒ„์ „์œผ๋กœ ๋Œ๋ฆด ์ˆ˜ ์žˆ๋‹ค.

 

git log -p

--- a/hello1.txt ~~~ +3

hello1.txt๋Š” ์ด ๋ฒ„์ „์—์„œ 3์ด๋ผ๋Š” ํ…์ŠคํŠธ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ๋‹ค.

 

---dev/null ~~~

hello2.txt๋„ ์ด ๋ฒ„์ „์— ํฌํ•จ๋˜๋Š”๋ฐ, ๋งˆ์ง€๋ง‰ ๋ฒ„์ „์€ ์—†์—ˆ๊ณ  ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€๋œ ํŒŒ์ผ์ด๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๊ทธ ์ถ”๊ฐ€๋œ ๋ฒ„์ „์—๋Š” 3์ด๋ผ๋Š” ํ…์ŠคํŠธ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ๋‹ค.

 

checkout๊ณผ ์‹œ๊ฐ„์—ฌํ–‰

master: ๊ฐ€์žฅ ์ตœ์‹  ๋ฒ„์ „์ด๋ผ๊ณ  ์ƒ๊ฐ.

HEAD -> master: ํ˜„์žฌ ์šฐ๋ฆฌ์˜ ์ƒํƒœ๊ฐ€ ์ตœ์‹  ๋ฒ„์ „์„ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ์Œ.

๊ณผ๊ฑฐ๋กœ ๋Œ์•„๊ฐ€๋ ค๋ฉด, HEAD๋ฅผ ๋‹ค๋ฅธ ๋ฒ„์ „์„ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ํ•˜๊ธฐ.

 

git checkout ๋ฒ„์ „ ์ด๋ฆ„(commit ๋’ค์— ์žˆ๋Š” ๊ธด ๊ธ€์ž๋“ค)

Message2๋กœ checkout.

 

git log

Message3๊ฐ€ ์‚ฌ๋ผ์ง„ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

HEAD๋„ master๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ์ง€ ์•Š๊ณ , Message 2 ๋ฒ„์ „์„ ๊ฐ€๋ฆฌํ‚ค๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Œ.

BUT Message 3 ๋ฒ„์ „์ด ์ง€์›Œ์ง„ ๊ฒƒ์€ ์•„๋‹˜!!

 

git checkout master

๋‹ค์‹œ ์›๋ž˜๋Œ€๋กœ ๋ณต์›~!