8

私についてのいくつかの質問を読んだ後.gitignore、私の質問に答えることができる人は誰も見つかりませんでした:

すべてのフォルダなど、特定の末尾のすべてのファイルを無視するには、.gitignoreに何を追加する必要が ありますか*.txt

.gitignoreトップレベルのファイルは1つだけにしたいです。

私はいくつかのことを試しましたが、どれもうまくいきませんでした。

これは私がテストしたものです(.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ですか?

4

1 に答える 1

3

追加するだけで機能し*.txtます。gitignore 形式の説明については、gitignore(5) の man ページを確認してください。

ディレクトリを追加しようとするとcontent、すべての*.txtファイルが無視されます。

$ echo "*.txt" > .gitignore 

$ git add content

$ git status --ignored --untracked-files=all
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   content/def.other
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
# Ignored files:
#   (use "git add -f <file>..." to include in what will be committed)
#
#       abc.txt
#       content/abc.txt
#       content/def.txt
于 2012-05-16T12:03:38.410 に答える