игнорировать определенные файлы во всех папках, используя один файл .gitignore

Прочитав несколько вопросов о .gitignoreя не нашел никого, кто мог бы ответить на мой вопрос:

Что мне нужно добавить в .gitignore, чтобы игнорировать все файлы с определенным окончанием, скажем *.txtво всех папках.

Я бы предпочел иметь только один файл .gitignoreна верхнем уровне.

Я пробовал несколько способов, но ничего не помогло.

Вот что я протестировал (.gitignoreбыл добавлен в репозиторий ранее, никаких других файлов не добавлялось):

  $ 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")

Это ожидаемо: все файлы отображаются, так как .gitignore пуст.

  $ 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")

Почему файлы content/abc.txt и content/def.txt не отображаются в списке?

  $ git clean -n
  Would not remove content/

Я думал, что они появятся и здесь.

  $ 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

Если файлы content/abc.txt и content/def.txt показаны с помощью clean -n -x, но не с помощью clean -n, я думаю, что они игнорируются. Но тогда почему они не отображаются в git status --ignored --untracked-files=all?

7
задан Onur 16 May 2012 в 11:44
поделиться