git - 如何让 git 忽略 .gitignore 中的忽略

标签 git gitignore git-status

我有一个包含 .gitignore 文件的 Git 存储库,其中列出了一些要忽略的文件(在构建过程中创建)。

$ cat .gitignore
foo
$ ls
bar
$ git status
On branch master
nothing to commit, working directory clean
$ touch foo
$ ls
bar foo
$ git status
On branch master
nothing to commit, working directory clean
$

在该存储库的特定克隆中,我确实想要查看 .gitignore 中列出的文件。

这可以通过 --ignored 选项到 git status 来完成:

$ git status
On branch master
nothing to commit, working directory clean
$ git status --ignored
On branch master
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    foo

nothing to commit, working directory clean
$

不错。我的问题是:我怎样才能使这个对于 given 存储库永久存在,这样我就不必记得添加 --ignored 标志?

$ git status
On branch master
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    foo

nothing to commit, working directory clean
$

我确定有一些 git 配置允许我配置我的克隆以忽略 .gitignore 的内容...

此外,我不想为所有 存储库设置此选项;仅供少数人使用。

最佳答案

您需要做的是为 $ git status 命令创建一个别名(我们称之为 istatus)。

$  git istatus
On branch master
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    foo

nothing to commit, working directory clean

怎么做是described here甚至还有 a similar question on SO .

TL;DR:基本上你只需要在 ~/.gitconfig 中添加几行:

[alias]
    istatus = status --ignored

关于git - 如何让 git 忽略 .gitignore 中的忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25909293/

相关文章:

Gitignore 排除所有子目录中的某些文件

linux - git repo 中的文件都已删除且未被跟踪,但它们仍然存在。这怎么可能?

Git 缓慢枚举不存在的未跟踪文件

尽管更改是远程进行的,但 Git 说是最新的

git - 使用 git 的高效项目架构

git - 使用 Go 包的修改分支代替已安装的包

git - 如何更改我在 GitHub 上的作者姓名?

git - 使用 git log,有没有办法在一个命令中获取 '--name-status' 和 '--numstat'?

Git 排除具有特定名称的目录,除了一个

git:每个 Remote 都有不同的 .gitignore 文件