Etc. Command
๋์๋ง ๋ณด๊ธฐ
help ๋ช ๋ น์ด๋ก ๊ฐ ๋ช ๋ น์ด ๋ฐ ์ต์ ์ ๊ธฐ๋ฅ์ ๋ํด ์ดํด๋ณผ ์ ์์
# Git์์ ์ ๊ณตํ๋ ๋ชจ๋ ๋ช
๋ น์ด ๋ณด๊ธฐ
$ git help -all
# ํน์ command์์ ์ฌ์ฉํ ์ ์๋ ๋ชจ๋ ์ต์
๋ณด๊ธฐ
$ git [command] -help
์ธํ
๋ฐ ์ด๊ธฐํ
Repository๋ฅผ ์ด๊ธฐํํ๊ฑฐ๋ ์กด์ฌํ๋ Repository๋ฅผ clone
# ํ์ฌ directory๋ฅผ ๊ธฐ์ค์ผ๋ก Git ์ ์ฅ์๊ฐ ์์ฑ
$ git init
# URL์ ํตํด remote Repository๋ฅผ local Repository์ ๋ณต์
$ git clone [url]
Stage & Commit
stage ์์ญ์ ์ด์ฉํ์ฌ commitํ ์ ์์
# ๋ค์ commit์ ์ํด ํ์ฌ directory์์ ์์ ๋ ํ์ผ์ ํ์ธํ ์ ์์
$ git status
# ๋ค์ commit์ ์ํด ํ์ผ์ ์ถ๊ฐ (stage)
$ git add [file]
# ์ถ๊ฐํ ํ์ผ์ unstaging: ๋ณ๊ฒฝ ์ฌํญ์ ์ ์ง๋จ
$ git reset [file]
# stage๋์ง ์์ ๋ณ๊ฒฝ ์ฌํญ์ ๋ณด์ฌ์ค
$ git diff
# stageํ์ง๋ง commitํ์ง ์์ ๋ณ๊ฒฝ ์ฌํญ์ ๋ณด์ฌ์ค
$ git diff --staged
# stage๋ ์ฝํ
์ธ ๋ฅผ ๋ฉ์์ง์ ํจ๊ป commit (snapshot ์์ฑ)
$ git commit -m โ[descriptive message]โ
๋น๊ต ๋ฐ ๊ฒ์ฌ
๋ก๊ทธ ๋ฐ ๋ณ๊ฒฝ ์ฌํญ์ ๊ฒ์ฌํ ์ ์์
# ๋ธ๋์นB์ ์๋ ๋ธ๋์นA์ ๋ชจ๋ commit ํ์คํ ๋ฆฌ๋ฅผ ๋ณด์ฌ์ค
$ git log branchB..branchA
# ํด๋น ํ์ผ์ ๋ณ๊ฒฝ ์ฌํญ์ด ๋ด๊ธด ๋ชจ๋ commit์ ํ์ (ํ์ผ ์ด๋ฆ ๋ณ๊ฒฝ๋ ํ์)
$ git log --follow [file]
# ๋ธ๋์นA์ ์์ง๋ง ๋ธ๋์นB์ ์๋ ๊ฒ์ ๋ณ๊ฒฝ ๋ด์ฉ(diff)์ ํ์ (branch๊ฐ ์ํ ๋น๊ต)
$ git diff branchB...branchA
๊ณต์ ๋ฐ ์
๋ฐ์ดํธ
ํน์ Repository์ ์ ๋ฐ์ดํธ ์ฌํญ์ ๊ฒ์ํ์ฌ local Repository๋ฅผ ์ ๋ฐ์ดํธ ํ ์ ์์
# url์ ํตํด ํน์ remote Repository๋ฅผ ๋ณ์นญ์ผ๋ก ์ถ๊ฐ
$ git remote add [alias] [url]
# ๋ณ์นญ์ผ๋ก ์ถ๊ฐํ remote Repository์ ์๋ ๋ชจ๋ ๋ธ๋์น ๋ฐ ๋ฐ์ดํฐ๋ฅผ local๋ก ๊ฐ์ ธ์ด
$ git fetch [alias]
# remote ๋ธ๋์น๋ฅผ ํ์ฌ ์์
์ค์ธ ๋ธ๋์น์ ๋ณํฉํ์ฌ ์ต์ ์ํ๋ก ๋ง๋ค ์ ์์
$ git merge [alias]/[branch]
# local ๋ธ๋์น์ commit์ remote ๋ธ๋์น๋ก ์ ์ก
$ git push [alias] [branch]
# remote Repository์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ ์๋์ผ๋ก local ๋ธ๋์น์ ๋ณํฉ
$ git pull
ํ์คํ ๋ฆฌ ์์
๋ธ๋์น ๋๋ commit์ ์์ ํ๊ฑฐ๋ commit ํ์คํ ๋ฆฌ๋ฅผ ์ง์ธ ์ ์์
# ํน์ ๋ธ๋์น์ ๋ถ๊ธฐ ์ดํ commit์ ํ์ฌ ์์
์ค์ธ ๋ธ๋์น์ ๋ฐ์
$ git rebase [branch]
# ๋์ commit ์ ์ผ๋ก ๋์๊ฐ๋ฉฐ stage๋ ๋ณ๊ฒฝ ์ฌํญ์ ๋ชจ๋ ์ง์
$ git reset --hard [commitish]
์์ ์ ์ฅ
๋ธ๋์น๋ฅผ ์ ํํ๊ธฐ ์ํด ๋ณ๊ฒฝ๋์๊ฑฐ๋ ์ถ์ ์ค์ธ ํ์ผ์ ์์๋ก ์ ์ฅํ ์ ์์
# ์์ ํ๊ฑฐ๋ stage๋ ๋ณ๊ฒฝ์ฌํญ์ ์คํ์ ์์ ์ ์ฅํ๊ณ ํ์ฌ ์์
๋ด์ญ์์ ์ง์
$ git stash
# ์คํ์ ์์ ์ ์ฅ๋ ๋ณ๊ฒฝ์ฌํญ์ ๋ชฉ๋ก์ ๋ณด์ฌ์ค
$ git stash list
# ์คํ์ ์์ ์ ์ฅ๋ ๋ณ๊ฒฝ์ฌํญ์ ๋ค์ ํ์ฌ ์์
๋ด์ญ์ ์ ์ฉ
$ git stash apply
# ์คํ์ ์์ ์ ์ฅ๋ ๋ณ๊ฒฝ์ฌํญ์ ๋ค์ ํ์ฌ ์์
๋ด์ญ์ ์ ์ฉํ๊ณ ์คํ์์ ์ญ์
$ git stash pop
# ์คํ์ ์์ ์ ์ฅ๋ ๋ณ๊ฒฝ์ฌํญ์ ์ญ์
$ git stash drop
Last updated