Git

Git ๋ฒ„์ „ ๊ด€๋ฆฌํ•˜๊ธฐ

๋…ธ๋ฃจ๋ฃฝ 2020. 7. 27. 22:47

Git ๋ฒ„์ „ ๊ด€๋ฆฌ ์‹œ์ž‘

๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํ•˜๊ณ ์ž ํ•˜๋Š” ํด๋”๋กœ ๋“ค์–ด๊ฐ€์„œ

git init .

(. ์€ ํ˜„์žฌ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์˜๋ฏธ)

 

(master)๋ผ๋Š” ํ‘œ์‹œ๊ฐ€ ์ƒ๊ธฐ๊ณ , .git์ด๋ž€ ํด๋”๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

.git์ด๋ž€ ํด๋”๋Š”, ํŒŒ์ผ์˜ history๊ฐ€ ์ €์žฅ๋˜๋Š” ํด๋”์ด๋ฏ€๋กœ ์ ˆ๋Œ€ ์ ˆ๋Œ€ ์‚ญ์ œํ•˜์ง€ ๋ง ๊ฒƒโ€ผโ€ผ

 

Git ๋ฒ„์ „ ์ƒ์„ฑ

  • Working tree: ๋ฒ„์ „์ด ๋˜๊ธฐ ์ „ ๋‹จ๊ณ„
  • Staging Area: ํŒŒ์ผ ์—ฌ๋Ÿฌ ๊ฐœ ์ค‘ ์ผ๋ถ€ ํŒŒ์ผ๋งŒ ๋ฒ„์ „์œผ๋กœ ๋งŒ๋“ค๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉ.git์€ Statging area์— ์žˆ๋Š” ํŒŒ์ผ๋งŒ ๋ฒ„์ „์œผ๋กœ ๋งŒ๋“ค์–ด์„œ repository์— ๋„ฃ๋Š”๋‹ค.
  • Repository: ๋ฒ„์ „์ด ์ €์žฅ๋˜๋Š” ๊ณณ (= .git)

ํŒŒ์ผ ์ƒ์„ฑ

nano hello1.txt

1 ์ž…๋ ฅ ํ›„, ctrl + x , y (ํŒŒ์ผ ์ €์žฅ)

cat hello1.txt๋กœ ์ž˜ ์ €์žฅ๋๋Š”์ง€ ํ™•์ธ.

 

git status

git status

Untracked๋Š” ์•„์ง git์ด ์ธ์‹ ๋ชปํ•œ๋‹ค๋Š” ๋œป → ์ด ํŒŒ์ผ์„ ๋ฒ„์ „ ๊ด€๋ฆฌํ•  ๊ฑฐ์•ผ๋ผ๊ณ  ํ•œ ๋ฒˆ ์•Œ๋ ค์ค˜์•ผ ํ•จ.

 

git add hello1.txt

Working tree์˜ ์ˆ˜์ •์‚ฌํ•ญ์„ Staging area์— ์˜ฌ๋ฆฐ๋‹ค.

 

git commit -m "Message1"

ํŒŒ์ผ์ด repository๋กœ ๊ฐ„๋‹ค.

 

commit ์™„๋ฃŒ!

 

(+) Please tell me who you are. ๋ฉ”์‹œ์ง€๊ฐ€ ๋œฌ ๊ฒฝ์šฐ

Please tell me who you are

git์˜ ์ดˆ๊ธฐ ์„ค์ •์„ ์•ˆ ํ•ด์ค˜์„œ ์ƒ๊ธด ์ผ.

git config --global user.email "์ด๋ฉ”์ผ"

git config --global user.name "์ด๋ฆ„"

์„ ์ž…๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

 

๋ฒ„์ „ ์ƒ์„ฑ ํ™•์ธ

git log

git log

๋‚˜๊ฐˆ ๋• q

 

hello1.txt ํŒŒ์ผ ์ˆ˜์ • ํ›„ ๋‹ค์‹œ git status

git status

ํŒŒ์ผ์ด ์ˆ˜์ •๋˜์—ˆ๋‹ค๊ณ  ๋œฌ๋‹ค.

๋‹ค์‹œ add ํ•ด์„œ stage์— ์˜ฌ๋ฆฌ๊ณ , commit ํ•œ๋‹ค. (Message 2)

working tree๊ฐ€ ๋น„์–ด์žˆ๋Š” ์ƒํƒœ

๋กœ๊ทธ ํ™•์ธ

git log

Message 2๊ฐ€ ์˜ฌ๋ผ๊ฐ€ ์žˆ๋‹ค.

 

์—ฌ๋Ÿฌ ๊ฐœ ํŒŒ์ผ์„ ๋ฒ„์ „์œผ๋กœ ๋งŒ๋“ค๊ธฐ

hello1.txt ์ˆ˜์ • && hello2.txt ์ƒ์„ฑ

git status

๋‘˜ ๋‹ค working tree์— ์˜ฌ๋ผ์™€ ์žˆ๋‹ค.

hello1.txt๋Š” ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํ•œ ์  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ธ์‹ํ•˜์ง€๋งŒ, hello2.txt์€ untracked์ƒํƒœ.

hello1๊ณผ 2 ๋‘˜ ๋‹ค add -> commit -> status -> log ํ™•์ธ

 

ํ•˜์ง€๋งŒ log์—๋Š” ๋ช‡ ๊ฐœ์˜ ํŒŒ์ผ์ด, ์–ด๋–ค ํŒŒ์ผ์ด ์—ฐ๋ฃจ๋˜์–ด ์žˆ๋Š”์ง€ ์•Œ ์ˆ˜ ์—†๋‹ค.

 

git log --stat

์–ด๋–ค ํŒŒ์ผ์ด, ๋ช‡ ์ค„ ์ˆ˜์ •๋˜์—ˆ๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.