๐ข 22/05/20 ๋ณต์ต
Smart Tiger's blog,https://seamless.tistory.com/43
LainyZine,https://www.lainyzine.com/ko/article/git-stash-usage-saving-changes-without-commit/
์ฐธ๊ณ ์ฌ์ดํธ์ ๋ด์ฉ์ ๊ฐ์ธ์ ์ผ๋ก ๋ณต์ตํ๊ธฐ ํธํ๋๋ก ์ฌ๊ตฌ์ฑํ ๊ธ์ ๋๋ค.
์์ธํ ์ค๋ช ์ ์ฐธ๊ณ ์ฌ์ดํธ๋ฅผ ์ดํด๋ณด์๊ธฐ ๋ฐ๋๋๋ค.
ํ์ฌ ์์นํ ๋๋ ํ ๋ฆฌ๋ฅผ git ์ ์ฅ์๋ก ๋ง๋ค์ด์ค๋ค.
.git
ํ์ผ์๋ ๋ฒ์ ๊ด๋ฆฌ๋ฅผ ์ํ ๋ฉํ ๋ฐ์ดํฐ๋ฅผ ํฌํจํ๊ณ , ํ ๋๋ ํ ๋ฆฌ์ ๋ฒ์ ๊ด๋ฆฌ๋ฅผ ๊ฐ๋ฅ์ผํ๋ค.
$ git init
$ ls -a # ".git" ํ์ผ ์์ฑ ํ์ธ
๊ธ๋ก๋ฒ ์ต์
์ ์ ์ฉํ๋ฉด ~/.gitconfig
ํ์ผ์ ์ ๋ณด๋ฅผ ์ ์ฅํ๊ณ , ์ ์ฉํ์ง ์์ผ๋ฉด ํ์ฌ ์์นํ ๋๋ ํ ๋ฆฌ์ <current directory>/.git/config
ํ์ผ์ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ค. ๋ก์ปฌ์์ ์ปค๋ฐํ ๋ ์ด ์ ๋ณด๋ฅผ ์ฌ์ฉํ๋ค.
https://www.lainyzine.com/ko/article/useful-git-settings-when-using-github-multi-account/
$ git config --global user.name <user name>
$ git config --global user.email <user email>
$ cat ~/.gitconfig
# [user]
# name = Your Name
# email = you@example.com
$ git config user.name <user name>
$ git config user.email <user email>
$ cat <current directory>/.git/config
# [user]
# name = Your Name
# email = you@example.com
# ์ ๋ณด ํ์ธ
$ git config --global user.name
$ git config --global user.email
$ git config user.name
$ git config user.email
# ์ ๋ณด ์ญ์
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git config --unset user.name
$ git config --unset user.email
push
๋๋ pull
์ ํ๊ธฐ ์ํ ์๊ฒฉ ์ ์ฅ์์ ์ฃผ์๋ฅผ ์ถ๊ฐ/์ญ์ ํ๋ ๊ธฐ๋ฅ์ ํ๋ค.
$ git remote -v
$ git remote add <remote name> <url>
$ git remote remove <remote name>
$ git remote show <remote name> # ๋ฆฌ๋ชจํธ ๋ธ๋์น์ ๋ก์ปฌ ๋ธ๋์น๊ฐ์ ๊ด๊ณ๋ฅผ ํ์ธํ ์ ์๋ค.
$ git remote prune <remote name> # ๋ฆฌ๋ชจํธ ๋ธ๋์น์ ์ ํจํ์ง ์์ ์ฐธ์กฐ๋ฅผ ์ง์ด๋ค.
์๊ฒฉ ์ ์ฅ์์ ๋ธ๋์น ๋ด์ฉ์ ๋ก์ปฌ ์ ์ฅ์๋ก ๊ฐ์ ธ์จ ํ ๋ณ๊ฒฝ ์ฌํญ์ ๋ณํฉํ๊ณ ์ถฉ๋ ์ฒดํฌ๋ฅผ ํด์ค๋ค.
$ git pull <remote name>
$ git pull <remote name> <branch name> # ์๋ ๋ช
๋ น์ด๋ฅผ ํ๋ฒ์ ์คํํ๋ ๊ฒ๊ณผ ๋์ผํ๋ค.
$ git fetch <remote name> <branch name>
$ git merge FETCH_HEAD
์๊ฒฉ ์ ์ฅ์์ ๋ธ๋์น ๋ด์ฉ์ ๋ก์ปฌ ์ ์ฅ์๋ก ๊ฐ์ ธ์จ๋ค.
$ git fetch <remote name> <branch name>
๋ณ๊ฒฝ ์ฌํญ์ ๋ณํฉํ๊ณ ์ถฉ๋ ์ฒดํฌ๋ฅผ ํด์ค๋ค.
$ git merge FETCH_HEAD
์๊ฒฉ ์ ์ฅ์์ git ํ๋ก์ ํธ๋ฅผ ๋ก์ปฌ ์ ์ฅ์๋ก ๊ฐ์ ธ์จ๋ค.
$ git clone <url> # ์๋ ๋ช
๋ น์ด๋ฅผ ํ๋ฒ์ ์คํํ๋ ๊ฒ๊ณผ ๋์ผํ๋ค.
$ git init
$ git remote add origin <url>
$ git pull origin master
$ git clone <url> <folder name> # ํด๋๋ช
์ง์ ๋ ๊ฐ๋ฅํ๋ค.
ํ์ฌ ๋ธ๋์น์ ํ์คํ ๋ฆฌ๋ฅผ ๋ณด๊ธฐ ์ํด ์ฌ์ฉํ๋ค.
$ git log
ํ์ฌ ์ํฌํ๋ ์ด์ค์ ์ํ๋ฅผ ๋ณด๊ธฐ ์ํด ์ฌ์ฉํ๋ค.
$ git status
์ํฌํ๋ ์ด์ค์์ ์์ ํ๋ ๋ด์ฉ์ ์คํ ์ด์ง ์์ญ์ผ๋ก ๋๊ฒจ์ค๋ค.
$ git add . # ์์ ํ ํ์ผ ์ ๋ถ๋ฅผ ๋๊ธด๋ค.
์์ ํ ๋ด์ฉ์ ๋๋๋ฆด ๋ ์ฌ์ฉํ๋ค.
$ git restore .
์คํ ์ด์ง ์์ญ์ ๋ด์ฉ์ ๋ฉ์ธ์ง๋ฅผ ์์ฑํ์ฌ ๋ก์ปฌ ์ ์ฅ์๋ก ๋๊ฒจ์ค๋ค.
$ git commit -m "message" # ๋ฉ์ธ์ง ์์ฑ
$ git commit --amend -m "message" # ๋ฉ์ธ์ง ์์
๋ก์ปฌ ์ ์ฅ์์ ๋ด์ฉ์ ์๊ฒฉ ์ ์ฅ์๋ก ๋๊ฒจ์ค๋ค.
$ git push <remote name> <branch name>
$ git push -u(--set-upstream) <remote name> <branch name> # -u ์ต์
์ ํตํด ๋ด์ฉ์ ๋๊ฒจ์ค ์๊ฒฉ ์ ์ฅ์๋ฅผ ์ง์ ํด๋๋ฉด ๋ค์ ํธ์ฌ๋ถํฐ๋ git push๋ง์ผ๋ก ๋ชฉ์ ์ง๋ฅผ ์ฐพ์๊ฐ๋ค.
์คํ ์ด์ง ์์ญ์ ์์ ๋ด์ฉ์ด๋ ์ปค๋ฐ ์ด๋ ฅ์ ๋๋๋ฆด ๋ ์ฌ์ฉํ๋ฉฐ, ์๊ฒฉ ์ ์ฅ์์ ์ฌ๋ผ๊ฐ ์ํ์์ ์ฌ์ฉํ์ง ์๋๋ค.
$ git reset # ์คํ
์ด์ง ์์ญ์ ์์
๋ด์ฉ์ ๋๋๋ฆฐ๋ค.
$ git reset --soft HEAD^ or <commit id> # ์ปค๋ฐ๋ ๋ด์ฉ์ ์คํ
์ด์ง ์์ญ์ผ๋ก ๋๋๋ฆฐ๋ค.
$ git reset --mixed HEAD^ or <commit id> # ์ปค๋ฐ๋ ๋ด์ฉ์ ์ํฌํ๋ ์ด์ค๋ก ๋๋๋ฆฐ๋ค.
$ git reset --hard HEAD^ or <commit id> # ์ปค๋ฐ๋ ๋ด์ฉ ๋ฐ ์์
์ค์ด๋ ๋ด์ฉ์ ์ ๊ฑฐํ๋ค.
์๊ฒฉ ์ ์ฅ์์ ์ฌ๋ผ๊ฐ ์ปค๋ฐ ์ด๋ ฅ์ ๋๋๋ฆด ๋ ์ฌ์ฉํ๋ฉฐ, ๋๋๋ฆฐ ์ด๋ ฅ์ ๋จ๊ธด๋ค.
$ git revert HEAD^ or <commit id>
๋ธ๋์น ๋ชฉ๋ก ๋ฐ ์์ฑ, ์ ๊ฑฐํ ๋ ์ฌ์ฉํ๋ค.
$ git branch -v
$ git branch -a
$ git branch -m <old branch name> <new branch name>
$ git branch -d|-D <branch name>
$ git branch <branch name>
๋ธ๋์น ์ด๋ ์ ์ฌ์ฉํ๋ค.
$ git switch <branch name>
$ git switch - # checkout์ผ๋ก ํน์ ์ปค๋ฐ์ผ๋ก ์ด๋ ์ ์๋ ๋ธ๋์น๋ก ๋์์ฌ ๋ ์ฌ์ฉํ๋ค.
ํน์ ์ปค๋ฐ ์ด๋ ฅ์ผ๋ก ์ด๋ ์ ์ฌ์ฉํ๋ค.
$ git checkout <commit number>
๋ค๋ฅธ ๋ธ๋์น์ ํน์ ์ปค๋ฐ์ ๊ฐ์ ธ์ค๊ณ ์ถ์ ๋ ์ฌ์ฉํ๋ค.
$ git cherry-pick <commit number>
$ git cherry-pick --quit # ์ฒด๋ฆฌํฝ ๋๋ด๊ธฐ
์์
๋์ค ๋ค๋ฅธ ์์ฒญ์ด ๋ค์ด์ค๋ฉด ์์
ํ๋ ๊ฑธ ๋ค๋ฅธ ์ฅ์์ ๋ณด๊ดํด๋๊ณ ์์ฒญํ ์์
์ด ๋๋๋ฉด ๊ธฐ์กด ์์
์ ๋ค์ ๊บผ๋ด์ฌ ๋ ์ฌ์ฉํ๋ค.
์ํฌํ๋ ์ด์ค์ ์คํ
์ด์ง ์์ญ์ ์๋ ์์ ๋ด์ฉ๋ค์ ์ฎ๊ธด๋ค.
$ git stash # ์์
ํ๋ ๋ด์ฉ์ ๋ค๋ฅธ ์ฅ์์ ๋ณด๊ดํ๋ค.
$ git stash -u # Untracked files๋ ํจ๊ป ์ฎ๊ฒจ์ค๋ค.
$ git stash -k # staged files๋ฅผ ์ ์ธํ๊ณ ์ฎ๊ฒจ์ค๋ค.
$ git stash save -m <message> # ๋ฉ์ธ์ง์ ํจ๊ป ๋ณด๊ดํ๋ค.
$ git stash list # ๋ณด๊ดํ ๋ด์ฉ์ ๋ชฉ๋ก์ ๋ณด์ฌ์ค๋ค.
$ git stash pop # ๋ณด๊ดํ ๋ด์ฉ์ ์ํฌํ๋ ์ด์ค๋ก ๊บผ๋ด์จ๋ค.
$ git stash pop --index # ๋ณด๊ดํ ๋ด์ฉ์ ๊ทธ๋๋ก ๊บผ๋ด์จ๋ค.(์คํ
์ด์ง ์์ญ)
$ git stash drop # ๋ณด๊ดํ ๋ด์ฉ์ ์ ๊ฑฐํ๋ค.