Po przeczytaniu kilku pytań o .gitignore
znalazłem nikogo, który mógłby odpowiedzieć na moje pytanie:ignorować pewne pliki ze wszystkich folderów za pomocą pojedynczego pliku .gitignore
Co mam dodać do .gitignore ignorować wszystkie pliki z pewne zakończenie, na przykład *.txt
we wszystkich folderach.
Wolałbym mieć tylko jeden plik .gitignore
na najwyższym poziomie.
Próbowałem kilku rzeczy, ale żaden nie działał.
To właśnie testowane (.gitignore
został dodany do repozytorium przed, żaden inny plik dodano):
$ ls
abc.txt content
$ ls content/
abc.txt def.other def.txt
$ echo "" > .gitignore
$ git status --ignored --untracked-files=all
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .gitignore
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# abc.txt
# content/abc.txt
# content/def.other
# content/def.txt
no changes added to commit (use "git add" and/or "git commit -a")
to zgodnie z oczekiwaniami: wszystkie pliki pokazać się od .gitignore jest pusty.
$ echo "*.txt" > .gitignore
$ git status --ignored --untracked-files=all
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .gitignore
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# content/def.other
# Ignored files:
# (use "git add -f <file>..." to include in what will be committed)
#
# abc.txt
no changes added to commit (use "git add" and/or "git commit -a")
Dlaczego zawartość plików/abc.txt i content/def.txt nie pojawia się na liście?
$ git clean -n
Would not remove content/
Myślałem, że również tutaj się pojawią.
$ echo "" > .gitignore
$ git clean -n
Would remove abc.txt
Would not remove content/
$ cd content
$ git clean -n -x
Would remove def.other
$ git clean -n -x
Would remove abc.txt
Would remove def.other
Would remove def.txt
Jeśli zawartość plików/abc.txt i content/def.txt są pokazane clean -n -x
ale nie przez clean -n
, myślę, że są one ignorowane. Ale dlaczego nie pojawią się w git status --ignored --untracked-files=all
?
Wydaje się, że powodem, ponieważ 'git status --ignored --untracked-files = all' nie pokazuje tych plików w swoim teście ma coś wspólnego z„katalog nie śledzone”(faktycznie może 'Śledzić katalogi, tylko pliki, ale kiedy śledziłem plik wewnątrz katalogu, który się pojawił) – KurzedMetal
To zadziałało. Dziwne jednak, że 'git clean -fx' usuwa tylko pliki w zawartości po tym, jak folder zawierał śledzony plik. W przeciwnym razie musiałem wywołać polecenie w samym folderze, aby usunąć pliki! – Onur