有没有办法告诉 git-status 忽略 .gitignore 文件的影响?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2994612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:32:15  来源:igfitidea点击:

Is there a way to tell git-status to ignore the effects of .gitignore files?

gitgitignoregit-status

提问by davidA

I have configured numerous .gitignorefiles to filter out many different unwanted files from a set of about 6,000 untracked files. I want to do git add .when I've got my filtered list looking the way I want it.

我已经配置了大量.gitignore文件,以从一组大约 6,000 个未跟踪的文件中过滤掉许多不同的不需要的文件。我想做的事情git add .时,我有我的过滤列表中寻找我想要的方式。

But, then I want to disable the .gitignorefilters temporarily to see what got left behind, and make sure there was nothing important accidentally filtered.

但是,然后我想.gitignore暂时禁用过滤器以查看留下了什么,并确保没有任何重要的意外过滤。

I know that git-cleanincludes an option to ignore .gitignore files. Is there a similar option for git-status?

我知道这git-clean包括一个忽略.gitignore files. 有类似的选项git-status吗?

I could go through and delete all the .gitignorefiles, do the check, then restore them, but it seems there should be an easier way?

我可以通过并删除所有.gitignore文件,进行检查,然后恢复它们,但似乎应该有更简单的方法?

采纳答案by Blair Holloway

Try using git ls-files --other- it should list all files that git doesn't know about; i.e. those files that aren't in the repository and aren't ignored by .gitignore.

尝试使用git ls-files --other- 它应该列出 git 不知道的所有文件;即那些不在存储库中且不被.gitignore.

You can also use git ls-files --ignored --exclude-standardto see what files git is explicitly ignoring.

您还可以使用git ls-files --ignored --exclude-standard查看 git 明确忽略的文件。

回答by Penghe Geng

This option --ignoreddoes the trick:

这个选项--ignored可以解决问题:

git status --ignored



(Update 1) I found the --ignoredoption alone doesn't work in certain git installations, perhaps it's a git bug. In those cases, an additional -sworks for me:



(更新 1)我发现--ignored单独的选项在某些 git 安装中不起作用,也许这是一个 git 错误。在这些情况下,-s对我来说还有一个额外的工作:

git status -s --ignored

(Update 2) One user reported --ignoredoption is not supported in git version 1.7.0.4. My git version is 1.7.6. Another version 1.7.5.1 is the one that requires -s. You may try

(更新 2)--ignoredgit 版本 1.7.0.4 不支持一个用户报告的选项。我的 git 版本是 1.7.6。另一个版本 1.7.5.1 是需要-s. 你可以试试

git status -h

to see if --ignoredis supported.

看看是否--ignored支持。

回答by nalply

git clean -dXn

git clean -dXn

See: Git command to show which specific files are ignored by .gitignore

请参阅:显示 .gitignore 忽略哪些特定文件的 Git 命令

In fact this question seems to be a duplicate!

事实上,这个问题似乎是重复的!