git使用之错误分析及解决(持续更新)

2023-07-11,,

错误一:

 使用

 $ git push -u origin master
出现如下错误: error: src refspec master does not match any.
error: failed to push some refs to 'git@github.com:hahaha/ftpmanage.git'

分析及处理

 原因:

 本地仓库为空

 解决方法:使用如下命令 添加文件;

 $ git add add.php addok.php conn.php del.php edit.php editok.php ftpsql.sql index.php

 $ git commit -m "init files"

错误二:

$ git push -u origin master
Warning: Permanently added the RSA host key for IP address 'xx.xx.xxx.xxx' to the list of known hosts.
To git@github.com:hahaha/ftpmanage.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:hahahah/ftpmanage.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 之后在 push

 使用如下命令解决:

 复制代码
$ git pull --rebase origin master
warning: no common commits
remote: Counting objects: , done.
remote: Total (delta ), reused (delta ), pack-reused
Unpacking objects: % (/), done.
From github.com:hahah/ftpmanage
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: init files

错误三:

 git add .时 警告warning: LF will be replaced by CRLF in

分析及处理

 原因:这是由于 ,跨平台的开发情况下产生的。

 详细:

 格式化是许多开发人员在协作时,特别是在跨平台情况下,遇到的令人头疼的细小问题。 由于编辑器的不同或者Windows程序员在跨平台项目中的文件行尾加入了回车换行符, 一些细微的空格变化会不经意地进入大家合作的工作或提交的补丁中。不用怕,Git的一些配置选项会帮助你解决这些问题。

 git cofig core.autocrlf

 假如你正在Windows上写程序,又或者你正在和其他人合作,他们在Windows上编程,而你却在其他系统上,在这些情况下,你可能会遇到行尾 结束符问题。 这是因为Windows使用回车和换行两个字符来结束一行,而Mac和Linux只使用换行一个字符。 虽然这是小问题,但它会极大地扰乱跨平台协作。

 Git可以在你提交时自动地把行结束符CRLF转换成LF,而在签出代码时把LF转换成CRLF。用core.autocrlf来打开此项功能, 如果是在Windows系统上,把它设置成true,这样当签出代码时,LF会被转换成CRLF:

 $ git config --global core.autocrlf true

 Linux或Mac系统使用LF作为行结束符,因此你不想Git在签出文件时进行自动的转换;当一个以CRLF为行结束符的文件不小心被引入时你肯定想进行修正, 把core.autocrlf设置成input来告诉Git在提交时把CRLF转换成LF,签出时不$ git config –global core.autocrlf input在Windows系统上的签出文件中保留CRLF,会在Mac和Linux系统上,包括仓库中保留LF。

 如果你是Windows程序员,且正在开发仅运行在Windows上的项目,可以设置false取消此功能,把回车符记录在库中:

 $ git config --global core.autocrlf false

错误四:

 refusing to merge unrelated histories

分析及处理

 因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,这句代码是在git 2.9.2版本发生的,最新的版本需要添加--allow-unrelated-histories

 假如我们的源是origin,分支是master,那么我们 需要这样写git pull origin master ----allow-unrelated-histories需要知道,我们的源可以是本地的路径

错误五:

 提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。
提示:再次推送前,先与远程变更合并(如 'git pull ...')。详见
提示:'git push --help' 中的 'Note about fast-forwards' 小节。

分析及处理

引起这个问题是远程仓库和本地不同步引起的

解决方案:需要先获取远端更新并与本地合并,再git push
具体操作如下:
git fetch origin //获取远程更新
git merge origin/master //把更新的内容合并到本地分支

错误六:

使用$ git clone时出现server certificate verification failed. CAfile:/etc/ssl/certs/ca-certificates.crt CRLfile: none

分析及处理

解决方法:在执行$ git clone 之前,在终端输入:

export GIT_SSL_NO_VERIFY=

错误七:

clone时出现,unable to negotiate with 10.0.0.8: no matching key exchange methodfound. Their offer: diffie-hellman-group1-sha1

分析及处理

解决方法:在执行git clone之前,在终端输入:

export GIT_SSH_COMMAND='ssh -o KexAlgorithms=+diffie-hellman-group1-sha1'
这种方法每次新开git窗口,都需要重新输入export GIT_SSH_COMMAND
网上有说是因为客户端和服务器端git版本不一致导致的,也有说如果知道服务器ip,可以在C:\Users\Spring\.ssh下新建一个config文件,添加内容如下,但是好像不起作用: Host 10.0.0.8
KexAlgorithms +diffie-hellman-group1-sha1
还有一种方法就是,打开.bashrc文件,在终端输入:$ vim ~/.bashrc ,然后向.bashrc文件写入: export GIT_SSH_COMMAND='ssh -o KexAlgorithms=+diffie-hellman-group1-sha1'
保存并关闭。这样就不需要每次打开终端时都重新输入export GIT_SSH_COMMAND了。

错误八:

 在Windows上,使用git bash here,编译vs2013工程时,中文显示乱码

分析及处理

解决方法:打开git bash here,鼠标点击右键--> Options… --> Text --> Locale 选择zh_CN,Characterset 选择GBK,点击Apply,OK即可

错误九:

 在Windows上写的代码移到Linux上提交时,会提示DOS line ending (CRLF) found, use Unix line ending (LF) instead

分析及处理

解决方法:()、下载dos2unix,执行
sudo apt-get install dos2unit
()、对有问题的文件执行:
doc2unit ../xxx.cpp

错误十:

unable to negotiate with *.*.*.*: no matching key exchange methodfound. Their offer: diffie-hellman-group1-sha1

分析及处理

在Windows上更新了git 版本后,clone/pull时出现错误,

unable to negotiate with *.*.*.*: no matching key exchange methodfound. Their offer: diffie-hellman-group1-sha1

解决方法:在执行git pull/clone之前,输入:

export GIT_SSH_COMMAND='ssh -o KexAlgorithms=+diffie-hellman-group1-sha1'  

这种方法每次打开git窗口,都要重新输入一次。

可以在C:\Users\Spring\.ssh的config文件下,添加内容如下,[本人测试有作用]

Host *.*.*.*
KexAlgorithms +diffie-hellman-group1-sha1

错误十一:

error: RPC failed; curl  OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

分析及处理

下载的项目太大
方法1: 改成ssh推送 方法2: 把推送的缓存扩大
#首先设置通信缓存大小
git config http.postBuffer
#然后把缓存清除
git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <file/dir>' HEAD

git使用之错误分析及解决(持续更新)的相关教程结束。

《git使用之错误分析及解决(持续更新).doc》

下载本文的Word格式文档,以方便收藏与打印。