我试图确保 .ssh 目录的内容不会进入 Git 存储库:
执行S:~$ 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 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------
Run Code Online (Sandbox Code Playgroud)
然后我将它们取出如下:
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
Run Code Online (Sandbox Code Playgroud)
我有以下 .gitignore 文件
executeS:~/.ssh$ pwd
/home/dockcclubdjango/.ssh
executeS:~/.ssh$ cat .gitignore
.*
!/.gitignore
Run Code Online (Sandbox Code Playgroud)
但如果我这样做,“git add . -A”,我就会再次得到步骤 1 中的内容。我可以做什么来确保 .ssh 永远不会进入存储库?
你还需要
/.ssh行到你的.gitignore.ssh并将行添加到.gitignore)现在git add -A不会再添加回来(用Git 2.15.0测试)
关于第二个问题(“我该怎么做才能确保 .ssh 永远不会进入存储库?”):.gitignore不会阻止文件添加到存储库。您始终可以使用git add -f path/to/file.
| 归档时间: |
|
| 查看次数: |
2743 次 |
| 最近记录: |