gitignore 문제

gitignore 문제

이런 식으로 디렉토리의 *.log 파일이 어떤 git 트랜잭션에도 포함되지 않기를 .gitignore바랍니다.test

:> cat ~/test/.gitignore
*/*/*.log
*/*/*__pycache__*
*/*/*out

그러나 내 대화에 따르면 내 gitignore가 내가 기대하는 작업을 수행하도록 정의되어 있지 않습니다.

내 실수는 어디에 있습니까? 제가 대화를 잘못 이해한 건가요, 아니면 제 .gitignore가 제가 기대한 것과 다른 건가요?

:> git add .
===
:> git status
On branch master
Your branch is up to date with 'origin/master'.
===
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
    new file:   ftp.log
===
:> git restore --staged ftp.log 
===
:> git status
Untracked files:
(use "git add <file>..." to include in what will be committed)
    ftp.log
nothing added to commit but untracked files present (use "git add" to track)

답변1

디렉토리를 제외하려면 다음을 test사용하여 test디렉토리에 새 .gitignore를 추가 할 수 있습니다.

*.log

현재 콘텐츠를 바꿀 수도 있습니다 .gitignore.

*/*/*.log

그리고

**/*.log

.log프로젝트 디렉터리에 있는 모든 파일의 흔적을 제거합니다 .

답변2

https://git-scm.com/docs/gitignore

노력하다**/*.log

앞에 "**" 뒤에 슬래시가 오면 모든 디렉터리에서 일치함을 의미합니다. 예를 들어, "**/foo"는 "foo" 패턴과 마찬가지로 파일 또는 디렉터리 "foo"와 일치합니다. "**/foo/bar"는 "foo" 디렉토리 바로 아래에 있는 파일 또는 디렉토리 "bar"와 일치합니다.

답변3

익숙해지세요https://git-scm.com/docs/gitignore#_pattern_format

별표 "*"는 슬래시를 제외한 모든 항목과 일치합니다.

원하는 것은 *.log모든 */*/*/...하위 디렉터리의 모든 .log 파일과 일치하는 와일드카드입니다.

/foo/bar.gitignore는 하드 참조( ) 및 소프트 참조( foo/bar) 를 포함하여 저장소 루트를 참조하는 파일과 일치합니다 .

관련 정보