programing tip

git 저장소의 .pyc 파일 무시

itbloger 2020. 9. 20. 09:07
반응형

git 저장소의 .pyc 파일 무시


.pycgit의 파일을 어떻게 무시할 수 있습니까?

내가 그것을 넣으면 .gitignore작동하지 않습니다. 추적되지 않고 커밋을 확인하지 않아야합니다.


에 넣어 .gitignore. 그러나 gitignore(5)man 페이지에서 :

  ·   If the pattern does not contain a slash /, git treats it as a shell
       glob pattern and checks for a match against the pathname relative
       to the location of the .gitignore file (relative to the toplevel of
       the work tree if not from a .gitignore file).

  ·   Otherwise, git treats the pattern as a shell glob suitable for
       consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in
       the pattern will not match a / in the pathname. For example,
       "Documentation/*.html" matches "Documentation/git.html" but not
       "Documentation/ppc/ppc.html" or
       "tools/perf/Documentation/perf.html".

따라서 적절한 *.pyc항목에 대한 전체 경로를 지정 하거나 .gitignore저장소 루트 (포함)에서 시작하는 디렉토리 파일에 넣으십시오 .


다음과 같은 줄을 추가해야합니다.

*.pyc 

.gitignore저장소 초기화 직후 git 저장소 트리의 루트 폴더에 있는 파일에 추가합니다.

으로 ralphtheninja는 말했다 당신이 단지에 라인을 추가 할 경우, 사전에 그것을 할 것을 잊었다 경우, .gitignore파일을 이전에 최선을 다하고 .pyc당신이 저장소에서 제거해야하므로 파일은 여전히 추적됩니다.

Linux 시스템 (또는 MacOSX와 같은 "부모 및 아들")을 사용하는 경우 저장소의 루트에서 실행해야하는 다음 한 줄 명령으로 빠르게 수행 할 수 있습니다.

find . -name "*.pyc" -exec git rm -f "{}" \;

이것은 단지 다음을 의미합니다.

내가 현재있는 디렉토리에서 시작하여 이름이 확장자로 끝나는 모든 파일을 찾고 .pyc파일 이름을 명령에 전달합니다.git rm -f

*.pyc추적 된 파일로 git에서 파일을 삭제 한 후이 변경 사항을 저장소에 커밋 한 다음 마지막으로 파일에 *.pyc줄을 추가 할 수 있습니다 .gitignore.

( http://yuji.wordpress.com/2010/10/29/git-remove-all-pyc/ 에서 수정 됨 )


을 (를) 넣기 전에 저장소에 추가했을 것 *.pyc입니다 .gitignore.
먼저 저장소에서 제거하십시오.


답변에 대해 @Enrico에게 감사드립니다.

virtualenv를 사용하는 경우 .pyc현재 디렉토리 내에 여러 파일 이 더있을 것이며,이 파일은 그의 find 명령으로 캡처됩니다.

예를 들면 :

./app.pyc
./lib/python2.7/_weakrefset.pyc
./lib/python2.7/abc.pyc
./lib/python2.7/codecs.pyc
./lib/python2.7/copy_reg.pyc
./lib/python2.7/site-packages/alembic/__init__.pyc
./lib/python2.7/site-packages/alembic/autogenerate/__init__.pyc
./lib/python2.7/site-packages/alembic/autogenerate/api.pyc

모든 파일을 제거하는 것이 무해하다고 생각하지만 .pyc기본 디렉토리 파일 만 제거하려면 다음을 수행하십시오.

find "*.pyc" -exec git rm -f "{}" \;

그러면 app.pycgit 저장소에서 파일 만 제거됩니다 .

참고 URL : https://stackoverflow.com/questions/5551269/ignore-pyc-files-in-git-repository

반응형