.DS_Store 파일을 git에 포함시키지 않기

gitignore.io

문제점

MacOS 환경에서 매번 프로젝트를 만들고 repository를 커밋할때 .gitignore를 제대로 만들지 않으면 .DS_Store가 딸려서 올라간다. 문득 쉬는 시간에 이걸 해결할 방법은 없는지 궁금해졌다.

해결방법

이미 .DS_Store가 커밋되었다면 다음 명령어를 사용한다. .DS_Store를 찾아서 0번째 인자로 받고 이를 $ git rm하는 명령어이다.

find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch

모든 repository에서 제거하고 싶을 때는 다음의 명령어를 사용한다. DSStore가 상위 폴더에 있을 때나 이름이 `..DS_Store` 일 때도 포함하지 않을 수 있다.

$ echo ".DS_Store" >> ~/.gitignore_global
$ echo "._.DS_Store" >> ~/.gitignore_global
$ echo "**/.DS_Store" >> ~/.gitignore_global
$ echo "**/._.DS_Store" >> ~/.gitignore_global
$ git config --global core.excludesfile ~/.gitignore_global

고찰

조금 예상하기는 했지만 역시나 global.gitignore를 추가하는 명령어가 있었다. 생각해보면 $ git add를 할 때 current_directory.gitignore을 읽기도 하지만 ~/.gitignore_global도 읽는구나 예측해볼 수 있다.

출처: .gitignore all the .DS_Store files in every folder and subfolder - Stack Overflow 검색어: ignore ds_store global


Philographer
Written by@Philographer
Fail Fast, Learn Faster

GitHublinkedInFacebook