Git ignore
1..gitignore
commit을 원하지 않는 파일을 git이 ignore하도록 관리하기 위한 파일
touch .gitignore
(.git
이 위치한 디렉토리(최상위)에 생성)nano .gitignore
- 파일 이름 입력
.gitignore
에 존재하는 파일이 계속해서 commit 목록에 남아있을 경우
-
git rm -r --cached .
: 모든 캐시 삭제 (프로젝트 디렉토리에서) -
git add .
: 모두 add -
git commit -m "Fix: fix untracked files"
: 커밋
2.Globbing
.gitignore
디렉토리에 제외할 파일을 모두 넣을 필요없이, globbing을 이용해 같은 효과를 낼 수 있다.
-
#
- marks line as a comment *
- matches 0 or more characters?
- matches 1 character[abc]
- matches a, b, _or_c**
- matches nested directories -a/**/z
matches (ex. a/z, a/b/z, a/b/c/z, 등)
sample폴더 안의 JPEG파일을 제외할 경우,
:
nano .gitignore
*.jpg 입력
활용
-
패턴 정의(globbing)
*.jpg / a??.pdf 등
-
특정 디렉토리 제외
nano .gitignore /디렉토리명 입력
-
특정 디렉토리 하위 특정 파일 제외
nano .gitignore /디렉토리명/디렉토리명/*.txt 입력 => 특정 디렉토리 .txt파일 제외
-
제외시켜선 안되는 필수 파일
nano .gitignore !.mvn/wrapper/maven-wrapper.jar => .mvn/wrapper/maven-wrapper.jar 파일은 절대 제외시키지 않음