Git 问题及解决方案
1. git 已经在 .gitignore
中忽略某个文件,还是会进行提交
解决方法:
在 .gitignore
中添加后,清除一下此文件的 git 缓存,然后再进行 commit
和 push
即可。
$ git -rm -r --cached 文件名
# 或者
$ git rm -r --cached .
$ git add .
$ git commit -m 'update .gitignore'
2. git push
时出现错误
错误如下:
remote: [err=06] Non fast-forward push to refs/heads/xxx is denied.
remote: 分支 (refs/heads/xxx) 不接受非 Fast-Forward 形式的推送
remote: error: hook declined to update refs/heads/xxx
解决方法:
$ git pull origin branchName --allow-unrelated-histories
或者
$ git pull --rebase origin branchName
这时会出现
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
输入
$ git config pull.rebase false
$ git push
3. github 后台配置 ssh key 之后本地无法 git clone 的问题 Permission denied (publickey)
.
当你在 github 后台添加了 ssh keys 之后,如果你在本地 git clone git://xxxxx/test.git
的时候出现了一些问题,不如 access denied,那么你要在本地这么测试一下:
ssh -T git@github.com
如果返回是:
Permission denied (publickey).
那么你可能要在本地 ssh-add
一下,当然在这之前你可以使用 ssh -vT git@github.com
查看一下到底是因为什么原因导致的失败。
ssh-add ~/.ssh/youraccount_rsa
然后会返回如下:
Enter passphrase for /Users/andy/.ssh/youraccount_rsa: Identity added: /Users/andy/.ssh/youraccount_rsa (/Users/andy/.ssh/youraccount_rsa)
之后再使用 ssh -T git@github.com
会返回成功:
Hi youraccount! You've successfully authenticated, but GitHub does not provide shell access.
说明你目前本地的 ssh 已经切换到了 youraccount 这个账号,
之后便可以进行 git clone 到本地:
git clone git@github.com:youraccount/yourproject.git
另:如果你有使用 github 官方的那个小猫 app,那么当你 git -T git@github.com
的时候会使用你在 github 这个程序中设置的 github 账号进行登录,而不是 ssh 的 rsa 账号登录。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: 了解 Git
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论