可將gitignore設定在以下三個地方,各代表不同意思

  • .gitignore

放在跟.git資料夾同一層
設定在這邊的代表此project需要忽略的,且此檔案會commit到git上,所以個人相關的不要放在這(ex: IDE產生的考慮放到下面那兩個)

.gitignore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# If you need to exclude files such as those generated by an IDE, use
# $GIT_DIR/info/exclude or the core.excludesFile configuration variable as
# described in https://git-scm.com/docs/gitignore
*.egg-info
*.pot
*.py[co]
__pycache__
MANIFEST
dist/
docs/_build/
docs/locale/
node_modules/
tests/coverage_html/
tests/.coverage
build/
tests/report/

  • $GIT_DIR/info/exclude
    $GIT_DIR通常就是.git folder
    設定在這邊的代表此project需要忽略的,不會被commit到git,專用來放個人相關的忽略

  • core.excludesFile
    全域忽略,所有project相關,在~/.gitconfig有此變數可設定