๐GIT checkout VS reset
โก checkout์ head๋ฅผ ๋ฐ๊พผ๋ค.
git checkout A : ์์ ๋๋ ํ ๋ฆฌ๋ A๋ฒ์ ์ด๋๋ค.
์๊ฐ์ฌํ์ ํ๋ ๊ฒ
git checkout main : ํค๋๋ฅผ ๋ฉ์ธ์ผ๋ก ๋ฐ๊พผ๋ค.
์ํน๋๋ ํ ๋ฆฌ๋ ๋ค์ B์ ๊ฐ์์ง๋ค. ์๊ฐ์ฌํ์ ๋๋ธ ๊ฒ
โก reset์ head์ branch๋ฅผ ๋ฐ๊พผ๋ค.
git reset A : head๊ฐ ๊ฐ๋ฆฌํค๋ branch์ธ main์ A๋ก ๋ฐ๊พผ๋ค.
B ๋ฒ์ ์ ์ญ์ ํ๋ ๊ฒ.
git reset B : main์ด B๋ฅผ ๋ค์ ๊ฐ๋ฆฌํค๊ฒ ํ๋ค.
B ๋ฒ์ ์ ์ญ์ ํ๋ ๊ฒ. B๋ ๋ณต์๋ ๊ฒ.
์ด ์ํ์์ git checkout B ํ๋ฉด
์ด ์ํ์์ ๋ค์ git reset A ํ๋ฉด?
ํ์ฌ head๊ฐ ๊ฐ๋ฆฌํค๋ branch๋ ์๊ธฐ ๋๋ฌธ์ head๊ฐ ์ง์ A๋ฅผ ๊ฐ๋ฆฌํจ๋ค.
์ถ์ฒ : ์ํ์ฝ๋ฉ ์ผ์ธ @coohde
๐ .gitignore
Here is a .gitignore file in one of my Laravel based project -
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
/.idea
/.vscode
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
.phpunit.result.cache
# personal rules
/site-content
/temp-files
*.log
๊น์ ๊ธฐ๋ณธ์ ์ผ๋ก ๊น์ด ์ค์ ๋ ํด๋ ํ์์ ์๋ ๋ชจ๋ ํ์ผ์ ํธ๋ํน
์ฐ๋ฆฌ๊ฐ ์ธ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์นํด์ ์ฌ์ฉํ ๋๋ ๋ชจ๋ ์ฝ๋๊ฐ ๊น์ ํธ๋ํน
ํนํ npm install ๋ง์ด ์ฌ์ฉํ๋ฉด ํ์ฌ ๋๋ ํ ๋ฆฌ์์ package.json ํ์ผ์ ์ฝ๊ณ ๊ทธ ์์ ์ ์๋ ์์กด์ฑ๋ค์ด ๋ชจ๋ ํด๋์ ์๋์ผ๋ก ์ค์น๋๋ค.
์ด ๋ ๋ณ๋์ `.gitignore`๋ฅผ ์ค์ ํ์ง ์๊ณ git add ๋ commit์ ํ๊ณ push๋ฅผ ํ๋ฉด ์ค์น๋ ๋ชจ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์ ํ์ผ๋ค์ด ๊นํ๋ธ์ ๊ฐ์ด ์ฌ๋ผ๊ฐ๊ฒ ๋๋ค. ์ด dummy๋ฅผ ํจ๊ป ํธ๋ํนํ๊ณ ์ถ์ง ์์ ๋ ์ฐ๋ ๊ฒ์ด `.gitignore`์ด๋ค. ํ๋ก์ ํธ ์ต์์ ํด๋์ .gitignore์ด๋ผ๋ ์ด๋ฆ์ ๊ฐ์ง ํ์ผ์ ๋ง๋ค์ด ์ฃผ๊ณ , ํธ๋ํนํ์ง ์๋ ํด๋๋ ํ์ผ์ ์ง์ ์จ ๋ฃ์ผ๋ฉด ๊ทธ๊ฒ๋ค์ ๊น์ ์ํด์ ๊ด๋ฆฌ๋์ง ์๋๋ค. ๊ทธ๋์ ํด๋น ํ์ผ๋ค์ ์คํ ์ด์ง ์์ญ์ ์ฌ๋ผ๊ฐ์ง ์๋๋ค.
โก .gitignore ์ฌ์ฉ๋ฒ
ํฐ๋ฏธ๋์ ์๋ ๋ช ๋ น์ด ์ ๋ ฅ ํ ์คํํ๊ธฐ
touch .gitignore
์ด ๋ช ๋ น์ด๊ฐ ์คํ๋๋ฉด ์ด๋ฆ์๋ ๋น ๋ฌธ์ ํ๋๊ฐ ๋ ํ์งํ ๋ฆฌ์ ์๋ก ์์ฑ๋๋ค.
์ฌ๊ธฐ์ ํธ๋ํน ํ์ง ์์ ํด๋๋ ํ์ผ์ ์ถ๊ฐ ํด ์ค๋ค.
โก.gitignore ํ์ผ ๋ฌธ๋ฒ
* (Asterisk) is used as a wildcard match i.e - *.log
/ (Forward slash) is used to ignore pathnames relative to the .gitignore file i.e - /temp-files
# (Number sign or Hash) is used to add comments to a .gitignore file i.e - # My custom rules
`*`๋ ์์ผ๋์นด๋๋ก, ํด๋น ํจํด์ ์ผ์นํ๋ ๋ชจ๋ ํ์ผ์ ์๋ฏธํ๋ค. ์๋ฅผ ๋ค์ด, `*.log`๋ `.log` ํ์ฅ์๋ฅผ ๊ฐ์ง ๋ชจ๋ ํ์ผ์ ๋ฌด์ํ๋ค.
`/` ์ฌ๋์๋ `.gitignore` ํ์ผ์ด ์์นํ ๊ฒฝ๋ก๋ฅผ ๊ธฐ์ค์ผ๋ก ์๋์ ์ธ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ๋ค.. ์๋ฅผ ๋ค์ด, `/temp-files`๋ ๋ฃจํธ ๋๋ ํ ๋ฆฌ ์๋์ ์๋ temp-files ํด๋๋ฅผ ๋ฌด์ํ๋ค.
`#` ์พ์ ์ฃผ์์ ์ถ๊ฐํ๋ ๋ฐ ์ฌ์ฉ๋๋ค. ์ฃผ์์ Git์ ์ํฅ์ ๋ฏธ์น์ง ์๋๋ค.
โกNode.js ์์ ์ผ๋ฐ์ ์ผ๋ก .gitignore ํด ์ฃผ๋ ํ์ผ๋ค
- node_modules/ ํด๋ (๋ชจ๋ ์ข ์์ฑ ํ์ผ)
- .log ํ์ฅ์๋ฅผ ๊ฐ์ง ๋ชจ๋ ํ์ผ (๋ก๊ทธ ํ์ผ)
- .env ํ์ผ (ํ๊ฒฝ ์ค์ ํ์ผ)
- dist/ ํด๋ (๋น๋๋ ๊ฒฐ๊ณผ๋ฌผ)
ํฌ์คํ ์ ์ฐธ๊ณ ํ ๋ธ๋ก๊ทธ
https://coderomeos.org/gitignore-file-and-its-usage
Understanding .gitignore in Git
A .gitignore file in a repository tells to Git what file or directory to be ignored in the repository. To ignore any files or directory we create rules in .gitignore file residing in the root of the repository.
coderomeos.org
https://codingbash.com/tutorial/how-to-use-gitignore-file-in-git
Git Ignore
In this article, we will learn how to use .gitignore file to ignore the untracked files intentionally.
codingbash.com