Git错误解决(windows版本下的Git Shell)

Posted lanshanxiao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git错误解决(windows版本下的Git Shell)相关的知识,希望对你有一定的参考价值。

第一个问题:怎么也不能将自己本地仓库代码pull到GitHub网站上?

git push origin master

Warning: Permanently added ‘github.com,192.30.255.112‘ (RSA) to the list of known hosts.
To github.com:lanshanxiao/yunweather.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘[email protected]:lanshanxiao/yunweather.git‘
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull ...‘) before pushing again.
hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.

 

 git pull origin master

Warning: Permanently added ‘github.com,192.30.255.112‘ (RSA) to the list of known hosts.
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
warning: no common commits
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:lanshanxiao/yunweather
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories

 

 git push origin master

Warning: Permanently added ‘github.com,192.30.255.112‘ (RSA) to the list of known hosts.
To github.com:lanshanxiao/yunweather.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘[email protected]:lanshanxiao/yunweather.git‘
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull ...‘) before pushing again.
hint: See the ‘Note about fast-forwards‘ in ‘git push --help‘ for details.

 

以上执行了三次,但是都报错,虽然pull下来远程仓库的代码,但是没有 

git pull origin master//将本地仓库代码和远程仓库代码融合

如果有下面的报错:

fatal: refusing to merge unrelated histories//说明本地仓库不能和远程仓库代码融合

就强制允许融合:

git pull origin master --allow-unrelated-histories

 

第二个问题:尽管已经添加了SSH密码到GitHub上,但是还是会出现Permission denied (publickey)?你可能没有将公钥添加到本机上

Warning: Permanently added ‘github.com,192.30.255.112‘ (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

首先,按照百度上的解决步骤,将SSH密码(C:\Users\用户名\.ssh\id_rsa.pub)中的密码加到自己的GitHub网站上,这个可以百度。

再次运行git push origin master 还是出现上面的错误,接下来就是重点:

ssh-agent.exe//运行agent

ssh -vT [email protected]

ssh-add -l//小写字母L

ssh-add

ssh-add -l//小写字母L

上面命令是将ssh运行在本机,并将公钥添加进来。

 

git ls-files//查看已经提交的文件。





























以上是关于Git错误解决(windows版本下的Git Shell)的主要内容,如果未能解决你的问题,请参考以下文章

windows下git中sh.exe中文显示乱码问题解决

Git----Windows下的安装教程

git版本控制工具的使用

[工具] Git版本管理

sh git:如何使用brew在OSX中解决“SSLRead()返回错误-9806”

怎样使用windows下的git