[GIT] β‘οΈ .gitignore π― μμ± μ 리 (μλ μμ± + μμ± κ·μΉ)
.gitignore νμΌμ΄λ?
νλ‘μ νΈμ μνμ§ μλ λ°±μ
νμΌμ΄λ λ‘κ·ΈνμΌ νΉμ μ»΄νμΌ λ νμΌλ€μ Gitμμ μ μΈμν¬ μ μλ μ€μ νμΌμ λ§νλ€.
μλ₯Όλ€μ΄ κΉνλΈμ 컀λ°ν λ νμνμ§ μλ νμΌμ μ
λ μν€μ§ μλ κΈ°λ₯μ΄λ€.
νμΌμ μ μΈμν΄μΌλ‘μ μ λ‘λ μ©λμ μ€μΌμλ μκ³ , μμ€ λ³΄μλ μ±κΈΈ μ μμ΄ μΌμμ΄μ£ μ΄λ€.
.gitignore μλμμ± μ¬μ΄νΈ
κ²μμ°½μ μ΄μ체μ , κ°λ°νκ²½(IDE), νλ‘κ·Έλλ° μΈμ΄λ₯Ό κ²μνλ©΄ .gitignore νμΌμ μλμΌλ‘ μμ±ν΄ μ€λ€.
gitignore.io
Create useful .gitignore files for your project
www.toptal.com
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env.production
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
### Node Patch ###
# Serverless Webpack directories
.webpack/
# Optional stylelint cache
.stylelintcache
# SvelteKit build / generate output
.svelte-kit
# End of https://www.toptal.com/developers/gitignore/api/node
κΉνλΈμ μλ΅λμ΄μΌν νμΌλ€μ΄ μ΄μ체μ , IDE, νλ‘κ·Έλλ°μΈμ΄λ³λ‘ μμ±μ΄ λκ³ κ·Έλλ‘ .gitignoreνμΌμ 볡λΆν΄μ€λ€. κ·Έ λ€μ, git bashλ‘ λͺ λ Ήμ΄λ₯Ό μ λ ₯νμ¬ μ μ©νλ€.
# μ€ν
μ΄μ§ λ κ²λ€ μΌλ¨ λͺ¨λ λλ리기. μλνλ©΄ addλ μνμμ .gitignoreκ° μν΅νκΈ° λλ¬Έ
$ git rm -r --cached .
$ git add .
$ git commit -m "Apply .gitignore"
ignore μ²λ¦¬λ νμΌ νμΈ
$ git status --ignored
.gitignore μμ± κ·μΉ
μ΄λ€ νμΌλ€μ μ»€λ° λμμμ μ μΈμμΌμΌ ν κΉ?
- IED toolκ³Ό κ΄λ ¨λ μ€μ νμΌ
- μΈμ΄μ λΉλ κ²°κ³Όλ¬Ό, λ‘κ·Έ, ν¨ν€μ§ κ΄λ ¨ νμΌ
- κ·Έ μΈ νλ‘μ νΈμμ μ¬μ©μκ° μ μΈνκΈ° μνλ νμΌ λ±λ±...
νλ‘μ νΈμμ μ΄λ€κ±Έ μ»€λ° λμμμ μ μΈ μμΌμΌ ν μ§ κΆκΈνλ€λ©΄ μλ μ¬μ΄νΈλ₯Ό μ°Έκ³ νμ. λ§μΌ λ Έλμμ 무μμ μ μΈν΄μΌ ν μ§ κΆκΈνλ©΄, Node.gitignore νμΌμ μ΄ν΄λ³΄λ©΄ λλ€.
GitHub - github/gitignore: A collection of useful .gitignore templates
A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.
github.com
.gitignore νμΌ κ·μΉ
νν | μλ―Έ |
#, λΉλΌμΈ | #μ μ£Όμμ μλ―Ένλ©°, λΉλΌμΈμ μλ¬΄λ° μν₯μ μ£Όμ§ μμ΅λλ€. |
*.a | νμ₯μκ° .a μΈ λͺ¨λ νμΌμ 무μν©λλ€. |
folder_name/ | ν΄λΉ ν΄λμ λͺ¨λ νμΌμ 무μν©λλ€. |
folder_name/*.a | ν΄λΉ ν΄λμ νμ₯μκ° .a μΈ λͺ¨λ νμΌμ 무μν©λλ€. |
folder_name/**/*.a | ν΄λΉ ν΄λ ν¬ν¨ν νμ λͺ¨λ ν΄λμμ νμ₯μκ° .a μΈ λͺ¨λ νμΌμ 무μν©λλ€. |
/*.a | νμ¬ ν΄λμ νμ₯μκ° .a μΈ λͺ¨λ νμΌμ 무μν©λλ€. |
.gitignore νμΌ μμ
# λͺ¨λ νμ₯μ .a νμΌμ 무μ
*.a
# 무μνλ λͺ¨λ νμ₯μ .a νμΌλ€ μ€μμ lib.a νμΌμ 무μνμ§ μμ
!lib.a
# Project/
# γ΄.gitignore
# γ΄A/
# γ΄a.txt
# γ΄TODO/
# γ΄tt.txt
# γ΄TODO/
# γ΄t.txt
# νμ¬ ν΄λ μ€μμ TODO ν΄λμ μλ λͺ¨λ νμΌμ 무μ
# (μ¦, t.txt νμΌλ§ 무μλκ³ tt.txt νμΌμ 무μλμ§ μμ)
/TODO
# νλ‘μ νΈ μ 체 ν΄λ μ€ TODOλΌλ ν΄λλͺ
μ μ¬μ©νλ TODO ν΄λμ νμ νμΌμ λͺ¨λ 무μ
# (μ¦, t.txt νμΌκ³Ό tt.txt νμΌ λͺ¨λ 무μλ¨)
TODO/
# Project/
# γ΄.gitignore
# γ΄doc/
# γ΄d.txt
# γ΄p.pdf
# γ΄server/
# γ΄ss.txt
# γ΄pp.pdf
# νμ¬ ν΄λ μ€μμ doc ν΄λ λ°λ‘ λ°μ μλ .txt νμ₯μ νμΌλ§ λͺ¨λ 무μ
# λ¨, doc/server/ss.txt μ κ°μ νμμμλ .txt νμ₯μ νμΌμ΄ 무μλμ§ μμ
doc/*.txt
# νμ¬ ν΄λ μ€μμ doc ν΄λ νμμ μλ .pdf νμ₯μ νμΌμ
# doc ν΄λ νμ μ΄λ€ ν΄λμ λ€μ΄ μλλΌλ λͺ¨λ 무μ
# (μ¦, p.pdf νμΌκ³Ό pp.pdf νμΌ λͺ¨λ 무μλ¨)
doc/**/*.pdf
.gitignore νμΌ μ΄μΈμ λ°©λ²λ€
.gitignore νμΌμ μ μ₯μ λ΄μ 컀λ°νμ¬ ν¬ν¨μν€λ κ²μ κΈ°λ³ΈμΌλ‘ νλ λ°©λ²μ΄λ€.
λ§μ½ νΉμ νμΌλ€μ λν κ·μΉμ μ μ₯μμ μ»€λ° μμ΄ ignore μ²λ¦¬νκΈ°λ₯Ό μνλ€λ©΄, μλμ κ°μ΄ λͺκ°μ§ μ νμ§κ° μ‘΄μ¬νλ€:
- .git/info/exclude νμΌμ μμ νλ€ (.gitignore νμΌμμμ λμΌν κ·μΉ λ¬Έλ²μ μ¬μ©νλ€).
κΈ°μ ν κ·μΉμ ν΄λΉ μ μ₯μ λ΄μ μ μμΌλ‘ μ μ©λ κ²μ΄λ€. - λ‘컬μ λͺ¨λ μ μ₯μλ€μ λν΄ λμΌν ignore μ²λ¦¬λ₯Ό νκ³ μΆλ€λ©΄ κΈλ‘λ² gitignore νμΌ μ€μ μ ν΄λλλ‘ νλ€
κΈλ‘λ² gitignore νμΌμ git config --global core.excludesfile <filepath> νμμΌλ‘ μ€μ
μΆκ°μ μΌλ‘, Git μ΄ κ΄λ¦¬μ€μΈ (tracked) νμΌλ€μ λν λ‘컬 λ³κ²½μ¬νλ€μ λ€μκ³Ό κ°μ λ°©λ²μΌλ‘ Git μ κΈλ‘λ² μ€μ μ λ³κ²½νμ§ μκ³ λ ignore μ²λ¦¬ν μ μλ€:
- git update-index --skip-worktree [<file>...]
: λ‘컬μλ§ μ μ©λμ΄μΌ ν μ€μ νμΌ μμ μ¬ν λ±μ΄ 컀λ°λμ§ μλλ‘ μ€μ νλ€ - git update-index --assume-unchanged [<file>...]
: SDKλ±κ³Ό κ°μ΄ μμ λμ΄μλ μλλ νμΌλ€μ λν΄ λ³κ²½ κ²μ¬λ₯Ό νμ§ μλλ‘ μ€μ νλ€
ignore μ²λ¦¬λ νμΌλ€ μ 리νκΈ°
git clean -X λͺ λ Ήμ΄λ₯Ό μ΄μ©νλ©΄ ignore μ²λ¦¬λ νμΌλ€μ μ κ±°ν μ μλ€:
#νμ¬ μμ
λλ ν 리μ μ‘΄μ¬νλ ignore μ²λ¦¬λ νμΌλ€μ λͺ©λ‘μ νμνλ€
$ git clean -Xn
#μ λͺ
λ Ήμ΄μ μν΄ λνλ νμΌλ€μ μμ νλ€
$ git clean -Xf
π Note:-X
(λλ¬Έμ) μ΅μ μ ignore μ²λ¦¬λ νμΌλ€λ§ μ 리νλ€.
ignore μ²λ¦¬λ νμΌλΏλ§ μλλΌ Gitμμ κ΄λ¦¬νμ§ μλ (untracked) νμΌκΉμ§ μ κ±°νλ €λ©΄
-x
(μλ¬Έμ) μ΅μ μ μ¬μ©νλ€.