git 学习笔记(问题解决)

1、know hosts warning

使用git时经常告警:

1
Warning: Permanently added '192.168.43.129' (RSA) to the list of known hosts.

解决方法:
C:\Users\youkegis.ssh目录下添加文件config,写入:UserKnownHostsFile ~/.ssh/known_hosts
保存后再次使用还会警告一次,之后就不会了

2、非标准ssh端口

若ssh服务器端口更改,用以下格式即可访问

1
git clone ssh://git@XXX.com:8120/username/resources.git

3、下载Github项目的发行文件

若要下载Github开源项目编译好的二进制文件等其他发行文件,可在项目主页点击Releases按钮或在项目URL后加“/releases”访问发行文件列表。

例如安卓端知名图片加载控件glide的github项目主页为:https://github.com/bumptech/glide
它的jar包下载页面路径为:https://github.com/bumptech/glide/releases

4、clone 超时

git clone的过程中报如下错误,clone失败

1
2
3
4
5
remote: Compressing objects: 100% (165/165), done.
packet_write_wait: Connection to 116.211.167.14: Broken pipe
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

解决方法:
打开git安装目录下的\ssh\ssh_config文件(E:\Study\git\PortableGit\etc\ssh\ssh_config)在“Host *”行下添加下面的配置,保存后即可解决:
ServerAliveInterval 120

5、error setting certificate verify

git clone github上的https链接报如下错误:

1
2
3
4
5
$ git clone https://github.com/Go-zh/tour.git
Cloning into 'tour'...
fatal: unable to access 'https://github.com/Go-zh/tour.git/': error setting certificate verify locations:
CAfile: E:\Program Files\PortableGit\mingw32/usr/ssl/certs/ca-bundle.crt
CApath: none

解决方法:
改问题主要是ca-bundle.crt文件的配置出错,使用下面的命令修改配置到正确的位置即可:
$ git config --system http.sslcainfo "E:\hsinan\Study\git\PortableGit\mingw32\ssl\certs\ca-bundle.crt"

6、同时访问不同源的git远程仓库

在同一台电脑上要用ssh的方式同时访问github.com(账户hsinan@outlook.com)和gitee.com(账户hsinan@qq.com)的方法:
先分别创建两个网站的ssh key:

1
2
3
4
#创建github的ssh key,文件名定为:id_rsa_github,自动生成私钥和公钥
ssh-keygen -t rsa -C "hsinan@outlook.com"
#创建github的ssh key,文件名定为:id_rsa_gitee,自动生成私钥和公钥
ssh-keygen -t rsa -C "hsinan@qq.com"

在~/.ssh下新建一个文件,命名为“config”,写入以下配置信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
#gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee
User Astian

#github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
User hsinan

如果设置过git的全局账号和邮箱需要用以下命令取消:

1
2
git config --global --unset user.name
git config --global --unset user.email

设置完成后测试连通性:

1
2
3
4
5
6
7
$ ssh -T git@gitee.com
Warning: Permanently added 'gitee.com,116.211.167.14' (ECDSA) to the list of known hosts.
Welcome to Gitee.com, Astian!

$ ssh -T git@github.com
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
Hi HSINAN! You've successfully authenticated, but GitHub does not provide shell access.

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!