1. 程式人生 > >Git錯誤解決(windows版本下的Git Shell)

Git錯誤解決(windows版本下的Git Shell)

git push allow yun hint forwards 用戶名 users shell using

第一個問題:怎麽也不能將自己本地倉庫代碼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)