你如何git显示.gitignore中不存在的未跟踪文件

jus*_*joe 152 git

git status -u用来显示未跟踪的文件.在终端上,我看到很多未跟踪的文件,我需要不跟踪,如单元测试,个人文档等.我已经把它们放进去.gitignore,但似乎git status仍然显示它们.

如何仅显示不存在的未跟踪文件.gitignore.

Mat*_*ugh 243

您可以按如下方式明确列出正在跟踪和未跟踪的内容,以查看Git是否正在查看并尊重您的内容.gitignore.如果您发布.gitignore内容,git status输出,dir或者ls我们可以更好地帮助您.

列出被忽略的文件

$ git ls-files . --ignored --exclude-standard --others
Run Code Online (Sandbox Code Playgroud)

列出未跟踪的文件

$ git ls-files . --exclude-standard --others
Run Code Online (Sandbox Code Playgroud)

  • 如果您看到您认为不在.gitignore中的文件,则可能还有另一个隐藏在您的项目中的文件.用它来发现它.-name .gitignore`. (3认同)
  • 为清楚起见,`git ls-files --others --exclude-standard --ignored` 列出未跟踪的忽略文件,而 `git ls-files --others --exclude-standard` 列出未跟踪的未忽略文件。更多关于它[这里](https://gist.github.com/x-yuri/06fc5dc1b8804f1204e4d615fd0d6b51)。 (2认同)