.gitignore 文件用于 ssh 目录

.gitignore file for ssh directory

我正在尝试确保 .ssh 目录的内容不会进入 Git 存储库:

executeS:~$ git diff --stat --cached origin/master

.gitignore           |   7 ------
 .ssh/.gitignore      |   2 ++
 .ssh/authorized_keys |   1 +
 .ssh/id_rsa          |  51 ++++++++++++++++++++++++++++++++++++++
 .ssh/id_rsa.pub      |   1 +
 .ssh/known_hosts     |   2 ++
 .viminfo             | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------

我再拿出来如下:

executeS:~$ git rm --cached .ssh/authorized_keys
rm '.ssh/authorized_keys'
executeS:~$ git rm --cached .ssh/id_rsa
rm '.ssh/id_rsa'
executeS:~$ git rm --cached .ssh/id_rsa.pub
rm '.ssh/id_rsa.pub'
executeS:~$ git rm --cached .ssh/known_hosts

我有以下.git忽略文件

executeS:~/.ssh$ pwd
/home/dockcclubdjango/.ssh

executeS:~/.ssh$ cat .gitignore
.*
!/.gitignore

但是如果我这样做了,"git add . -A",我就会明白我在第 1 步中的全部内容 再次。我该怎么做才能确保 .ssh 永远不会进入 存储库?

你还需要

  1. /.ssh 行添加到您的 .gitignore
  2. 提交所有更改(从 git 中删除 .ssh 并将行添加到 .gitignore

现在 git add -A 不会添加回来(使用 Git 2.15.0 测试)

关于第二个问题("What can I do to make sure that .ssh NEVER gets into the repository?"):.gitignore 不会阻止将文件添加到存储库。您始终可以使用 git add -f path/to/file.

添加被忽略的文件