Git新项目常见错误及处理
1、git重定向错误
示例:
fatal: unable to access 'https://github.com/xxx.git/': OpenSSL SSL_read: Connection was reset, errno 10054
或者
yf211@LAPTOP-7ETVDC6T MINGW64 /e/android/ (master)
$ git push -u origin master
fatal: unable to access 'https://github.com/xxx.git/': Failed to connect to github.com port 443 after 21078 ms: Timed out
处理:
git config --global --unset http.proxy
git config --global --unset https.proxy
2、git拉代码提示ssh key相关错误
示例:
Their offer: diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
fatal: Could not read from remote repository.
处理:
git config --global core.sshcommand "ssh -o KexAlgorithms=+diffie-hellman-group1-sha1"
如果出现:
# no matching host key type found. Their offer: ssh-rsa
Windows处理:
在C:\Users\yf211\.ssh添加config文件,内容如下:
Host *
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
Linux处理:
在/home/用户名/.ssh中添加config文件,内容同上。
3、Git代码回退
(1)查看回退改动:
git log
(2)回退某个文件:
git reset commitId xx.file
示例:
git reset 707e80f16a80fb89b7918822b184650db0108482 xx.file
(3)工作区文件内容覆盖远程分支文件(理解为恢复该文件改动):
git checkout xx.file
(4)版本号修改(如果需要手动修改文件内容):
vim xxx
(5)再次提交:
git add .
git commit -m "Revert changes"
git push
注意:在回退并修改版本号后,重新提交时可能会遇到远程分支已更新的情况,此时可能需要使用git push --force(慎用,因为它会覆盖远程分支的历史记录)或者使用git push --force-with-lease(更安全,仅在远程分支的更改不会与本地更改冲突时才推送)。