GIT

[GIT] ⚑️ .gitignore πŸ’― μž‘μ„± 정리 (μžλ™ 생성 + μž‘μ„± κ·œμΉ™)

인파_ 2021. 11. 20. 01:00

gitignore

.gitignore νŒŒμΌμ΄λž€?

ν”„λ‘œμ νŠΈμ— μ›ν•˜μ§€ μ•ŠλŠ” λ°±μ—… νŒŒμΌμ΄λ‚˜ 둜그파일 ν˜Ήμ€ 컴파일 된 νŒŒμΌλ“€μ„ Gitμ—μ„œ μ œμ™Έμ‹œν‚¬ 수 μžˆλŠ” μ„€μ • νŒŒμΌμ„ λ§ν•œλ‹€.
예λ₯Όλ“€μ–΄ κΉƒν—ˆλΈŒμ— μ»€λ°‹ν• λ•Œ ν•„μš”ν•˜μ§€ μ•ŠλŠ” νŒŒμΌμ€ μ—…λŽƒ μ‹œν‚€μ§€ μ•ŠλŠ” κΈ°λŠ₯이닀.

νŒŒμΌμ„ μ œμ™Έμ‹œν‚΄μœΌλ‘œμ„œ μ—…λ‘œλ“œ μš©λŸ‰μ„ μ€„μΌμˆ˜λ„ 있고, μ†ŒμŠ€ λ³΄μ•ˆλ„ μ±™κΈΈ 수 μžˆμ–΄ 일석이죠 이닀.


.gitignore μžλ™μƒμ„± μ‚¬μ΄νŠΈ

검색창에 운영체제, κ°œλ°œν™˜κ²½(IDE), ν”„λ‘œκ·Έλž˜λ° μ–Έμ–΄λ₯Ό κ²€μƒ‰ν•˜λ©΄ .gitignore νŒŒμΌμ„ μžλ™μœΌλ‘œ 생성해 μ€€λ‹€.

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

gitignore
gitignore

# 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 μž‘μ„± κ·œμΉ™

μ–΄λ–€ νŒŒμΌλ“€μ„ 컀밋 λŒ€μƒμ—μ„œ μ œμ™Έμ‹œμΌœμ•Ό ν• κΉŒ?

  1. IED toolκ³Ό κ΄€λ ¨λœ μ„€μ •νŒŒμΌ
  2. μ–Έμ–΄μ˜ λΉŒλ“œ κ²°κ³Όλ¬Ό, 둜그, νŒ¨ν‚€μ§€ κ΄€λ ¨ 파일
  3. κ·Έ μ™Έ ν”„λ‘œμ νŠΈμ—μ„œ μ‚¬μš©μžκ°€ μ œμ™Έν•˜κΈ° μ›ν•˜λŠ” 파일 λ“±λ“±...

ν”„λ‘œμ νŠΈμ—μ„œ μ–΄λ–€κ±Έ 컀밋 λŒ€μƒμ—μ„œ μ œμ™Έ μ‹œμΌœμ•Ό ν• μ§€ κΆκΈˆν•˜λ‹€λ©΄ μ•„λž˜ μ‚¬μ΄νŠΈλ₯Ό μ°Έκ³ ν•˜μž. 만일 λ…Έλ“œμ—μ„œ 무엇을 μ œμ™Έν•΄μ•Ό ν• μ§€ κΆκΈˆν•˜λ©΄, 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

 

.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 μ²˜λ¦¬ν•˜κΈ°λ₯Ό μ›ν•œλ‹€λ©΄, μ•„λž˜μ™€ 같이 λͺ‡κ°€μ§€ 선택지가 μ‘΄μž¬ν•œλ‹€:

  1. .git/info/exclude νŒŒμΌμ„ μˆ˜μ •ν•œλ‹€ (.gitignore νŒŒμΌμ—μ„œμ™€ λ™μΌν•œ κ·œμΉ™ 문법을 μ‚¬μš©ν•œλ‹€).
    κΈ°μˆ ν•œ κ·œμΉ™μ€ ν•΄λ‹Ή μ €μž₯μ†Œ 내에 μ „μ—­μœΌλ‘œ 적용될 것이닀.

  2. 둜컬의 λͺ¨λ“  μ €μž₯μ†Œλ“€μ— λŒ€ν•΄ λ™μΌν•œ 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
(μ†Œλ¬Έμž) μ˜΅μ…˜μ„ μ‚¬μš©ν•œλ‹€.