git - .gitignore 文件用于 ssh 目录

标签 git ssh gitignore

我正在尝试确保 .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

我有以下 .gitignore 文件

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

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

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

最佳答案

你还需要

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

现在 git add -A 不会把它加回去(用 Git 2.15.0 测试过)

关于第二个问题(“我能做些什么来确保 .ssh 永远不会进入存储库?”):.gitignore 不会阻止将文件添加到存储库。您始终可以使用 git add -f path/to/file 添加被忽略的文件。

关于git - .gitignore 文件用于 ssh 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47239132/

相关文章:

git - 非递归 git log 和 diff

git:分支分歧;如何进行?

git - git clone 是否复制所有源代码?

git - 如何在Golang中使用git2go在github中获取最新标签?

ssh - srun : error: Slurm controller not responding, sleeping and retrying

ssh - 即使以前工作过,EC2 SSH 端口 22 连接也被拒绝

使用公钥 ssh 登录仍然询问密码

Gitignore 双星模式不起作用

gitignore 不会忽略文件夹

java - 忽略maven目标文件夹但不忽略包 "target"