无法忽略 git 存储库中的 ssh 配置

Can't unignore ssh config in git repo

我的 Git bash 主目录受版本控制。我正在使用白名单(忽略所有内容 除了 ...):

$ cat .gitignore
# Ignore all the things
*

# But not these (with exceptions)
!*.bash_aliases
!*.bash_profile
!*.bashrc
!*.drush/
!*.drush/*
.drush/cache
!.gitconfig
!.gitignore
!.gitalias
!*.minttyrc
!*.vim/
!*.vim/*
.vim/.netrwhist
!*.vimrc

我想将 .ssh/config 添加到例外中,但我似乎还没有得到正确的语法。

$ ls .ssh/config
.ssh/config

我的 .gitignore 中有这一行:

$ git diff
diff --git a/.gitignore b/.gitignore
index 22b3a79..b84bcd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
 !.gitignore
 !.gitalias
 !*.minttyrc
+!.ssh/config
 !*.vim/
 !*.vim/*
 .vim/.netrwhist

然而它并没有被忽视:

~ (master)
$ git status
Changes not staged for commit:

        modified:   .gitignore

no changes added to commit (use "git add" and/or "git commit -a")

查看 .gitignore 中其他内容的语法,我尝试了这个:

$ git diff
diff --git a/.gitignore b/.gitignore
index 22b3a79..659d7be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
 !.gitignore
 !.gitalias
 !*.minttyrc
+!*.ssh/config
 !*.vim/
 !*.vim/*
 .vim/.netrwhist

无济于事:

$ git status
Changes not staged for commit:

        modified:   .gitignore

no changes added to commit (use "git add" and/or "git commit -a")

.gitignore 中添加 .ssh/config 作为例外的语法是什么?

git help ignore:

It is not possible to re-include a file if a parent directory of that file is excluded.

所以尝试添加:

!.ssh/

根据 jingx 的回答,我添加了这些行:

!*.ssh/
!*.ssh/config

它似乎奏效了:

$ git add .gitignore

$ git status
Changes to be committed:

        modified:   .gitignore
        new file:   .ssh/config

$ git add .ssh/known_hosts
The following paths are ignored by one of your .gitignore files:
.ssh/known_hosts
Use -f if you really want to add them.