.gitignore 공식문서
https://git-scm.com/docs/gitignore
Git - gitignore Documentation
The optional configuration variable core.excludesFile indicates a path to a file containing patterns of file names to exclude, similar to $GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to those in $GIT_DIR/info/exclude.
git-scm.com
.gitignore에서는 '!'를 맨 앞에 붙여 해당 파일/폴더/파일명을 예외 처리할 수 있다.
django 프로젝트에서는 작업완료 후, 매번 migrations 폴더에서 __init__.py 파일을 제외한 모든 파일을
일일이 삭제하고 commit, push 해야했다. 이 과정이 번거롭기도 하고 실수로 삭제하지 못하고 push 하는 경우가 종종 있어서
고민하던 중 해결방법을 찾았다.
해결 방법은 아래의 코드를 .gitignore에 추가하는 것이다. 해당 내용은 다음과 같다.
먼저 migrations 폴더 안의 모든 파일을 무시하도록 지정한 뒤, __init__.py 파일을 예외처리 해주는 것이다.
!migrations/__init__.py
migrations/* # 상황에 따라 '*' 삭제
migrations 폴더 안에 있는 파일 전체 무시 migrations/*
migrations 폴더 안에 있는 __init__.py 파일은 예외처리(무시하지 않음 ; commit에 반영) !migrations/__init__.py