Git basic
How to stacommit git
git init #make Local Repository .gitํด๋ ์์ฑ(hidden folder)
Working directory
๋ด๊ฐ ์ค์ ๋ก ์์ ํ๊ณ ์๋ ๋๋ ํ ๋ฆฌ
Staging Area
commit์ผ๋ก ๋จ๊ธฐ๊ณ ์ถ์, ํน์ ๋ฒ์ ์ผ๋ก ๊ด๋ฆฌํ๊ณ ์ถ์ ํ์ผ์ด ๋ชจ์ฌ์๋ ๊ณณ
git add {file name} # add to Staging Area
# addํ์ง ์์ file์ untracked ์ํ
# addํ file์ tracked ์ํ
git add {file name1} {file name2} # ์ฌ๋ฌ๊ฐ์ ํ์ผ add
git add . #ํ์ฌ folder๋ด์ ๋ชจ๋ file๋ค์ Staging Area๋ก add
Local Repository
Commit๋ค์ด ์ ์ฅ๋๋ ๊ณณ
git commit
gir commit -m "commit message" # Staging Area to Local Repository(committed)
# -m์ ์ฐ๋ฉด ํ์ค์ง๋ฆฌ commit message
Commit convention
์ปค๋ฐ ๋ฉ์์ง๋ฅผ ์์ฑํ ๋ ์ผ์ ํ ๊ท์น์ ๋ฐ๋ฅด๋ ๊ฒ
<type>(<optional scope>): <description>
[optional body]
[optional footer(s)]
ํ์ ์์
<type>
: ๋ณ๊ฒฝ ์ฌํญ์ ์ข ๋ฅ๋ฅผ ๋ํ๋.feat
: ์๋ก์ด ๊ธฐ๋ฅ ์ถ๊ฐfix
: ๋ฒ๊ทธ ์์ docs
: ๋ฌธ์ ๋ณ๊ฒฝstyle
: ์ฝ๋ ์คํ์ผ ๋ณ๊ฒฝ (๊ณต๋ฐฑ, ์ธ๋ฏธ์ฝ๋ก ๋ฑ ๋น์ฆ๋์ค ๋ก์ง ๋ฌด๊ด)refactor
: ์ฝ๋ ๋ฆฌํฉํ ๋ง (๊ธฐ๋ฅ ๋ณ๊ฒฝ ์์ด ๊ตฌ์กฐ ๊ฐ์ )test
: ํ ์คํธ ์ถ๊ฐ ๋๋ ์์ chore
: ๊ธฐํ ๋ณ๊ฒฝ์ฌํญ (๋น๋ ํ๋ก์ธ์ค๋ ํจํค์ง ์ค์ ๋ฑ)
<description>
: ๋ณ๊ฒฝ ๋ด์ฉ์ ๊ฐ๋ตํ ์์ฝ.
์ ํ ์์
<scope>
: ๋ณ๊ฒฝ๋ ํ์ผ์ด๋ ๊ธฐ๋ฅ์ ๋ฒ์๋ฅผ ๋ํ๋.๋ณธ๋ฌธ: ๋ณ๊ฒฝ ์ด์ , ์์ธ ์ค๋ช ๋ฑ ์ถ๊ฐ ์ ๋ณด๋ฅผ ์์ฑ.
ํธํฐ: ๊ด๋ จ ์ด์ ๋ฒํธ๋ ์ฐธ๊ณ ์ ๋ณด๋ฅผ ์ถ๊ฐ.
4.Remote Repository
GitHub๊ณผ ๊ฐ์ ์๋ฒ์ ์๋ ์ ์ฅ์
git push -u origin main(master)
# Local Repository to Remote Repository
# u = upstream. connect local branch and remote branch
# ์ต์ด pushํ ๋ upstream ์ค์ ์ดํ git push๋ก ๊ฐ๋จํ๊ฒ ์ฌ์ฉ
git push
git status # view working directory and staging area status
git log #view the commit history of a Git repository
git log --oneline # view simple log
git log -n <number> # ๊ฐ์ฅ ์ต๊ทผ์ N๊ฐ ์ปค๋ฐ๋ง ํ์
git log <file name> # ํน์ ํ์ผ์ ๋ํ ๋ณ๊ฒฝ ์ด๋ ฅ๋ง ํ์ธ
git log --graph # ์๊ฐ์ ์ผ๋ก ๋ณด์ฌ์ค
connect Local Repository with Remote Repository
commit๊ธฐ๋ฐ์ผ๋ก ์ฐ๊ฒฐ
Github์์ create New repository
git remote add origin {New repository https}
# https์ฃผ์๋ฅผ origin์ ํ ๋น(๊ด๋ก)
git push -u origin main(master)
git push
Remote Repository โ Local Repository
Clone
Github์์ Repository ์ ํ
git clone {repository https}
git push -u origin main
git push
git pull
open . # current folder open
start . # current folder open
code . # ํด๋น ํด๋์์ vscode๋ก open
Hiding file
.gitignore
# .gitignore์์ file and folder ์์ฑ
# ๋ฐ๋์ ๋ ํฌ์งํ ๋ฆฌ์ ๋ง๋ค์ด ๋๋๊ฒ์ด ์ข์
gitignore.io
venv/
config.py
.env
etc....
#ํ๋ฒ commit๋๋ฉด .gitignore์ ๋ฃ์ ์ ์์
Cancel commit
์ปค๋ฐ๋ง ์ทจ์ (ํ์ผ์ ๊ทธ๋๋ก)
git reset --soft HEAD~1
์ปค๋ฐ + git add ์ทจ์ (ํ์ผ ๋ณ๊ฒฝ ๋ด์ฉ์ ๋จ๊น)
git reset HEAD~1
์ปค๋ฐ + ํ์ผ ๋ณ๊ฒฝ ๋ด์ฉ๊น์ง ์ญ์
git reset --hard HEAD~1
ํน์ ํ์ผ๋ง ์ปค๋ฐ์์ ์ทจ์
git reset HEAD~1 ํ์ผ์ด๋ฆ
์๊ฒฉ ์ ์ฅ์์์๋ ์ทจ์ (๊ฐ์ ํธ์)
git push origin main --force
Last updated