我正在尝试确保 .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 永远不会进入 存储库?
最佳答案
你还需要
- 将
/.ssh
行添加到您的.gitignore
- 提交所有更改(从 git 中删除
.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/