Git 问题及解决方案

发布于 2025-01-09 21:03:17 字数 2413 浏览 6 评论 0

1. git 已经在 .gitignore 中忽略某个文件,还是会进行提交

解决方法:

.gitignore 中添加后,清除一下此文件的 git 缓存,然后再进行 commitpush 即可。

$ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

乖乖

暂无简介

文章
评论
25 人气
更多

推荐作者

迷鸟归林

文章 0 评论 0

alipaysp_h2Vbo4sv6k

文章 0 评论 0

清风无影

文章 0 评论 0

mnbvcxz

文章 0 评论 0

听不够的曲调

文章 0 评论 0

秋叶绚丽

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文