github各类疑难杂症汇集

179 阅读2分钟

#1 Failed to connect to github.com port 443: Timed out

6bfac3f67f94cb980e26513bfea78fd.png

# 取消全局代理:
git config --global --unset http.proxy 
git config --global --unset https.proxy

# 正确取消全局代理就能解决,不行的话再设置全局代理
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080

#2 删除某个需要上传的文件

## 比如删除根目录的gdj.zip文件
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch gdj.zip"  --prune-empty --tag-name-filter cat -- --all

#3 GitHub 无法读取远程仓库

tqsq2@LocoRoco MINGW64 /f/a-app/gdj (main)
$ ssh -T git@github.com
kex_exchange_identification: Connection closed by remote host
Connection closed by ::1 port 443

解决方案

$ ssh -vT git@github.com
OpenSSH_8.5p1, OpenSSL 1.1.1k  25 Mar 2021
debug1: Reading configuration data /c/Users/tqsq2/.ssh/config
debug1: /c/Users/tqsq2/.ssh/config line 1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to ssh.github.com [::1] port 443.
debug1: Connection established.
debug1: identity file /c/Users/tqsq2/.ssh/id_rsa type 0
debug1: identity file /c/Users/tqsq2/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_dsa type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_ecdsa_sk type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_ed25519_sk type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_xmss type -1
debug1: identity file /c/Users/tqsq2/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.5
kex_exchange_identification: Connection closed by remote host
Connection closed by ::1 port 443

额。。。看到问题没?!连接 github.com 的地址居然是 ::1 和 127.0.0.1,前者是 IPv6 的 localhost 地址,后者是 IPv4 的 localhost 地址。

这应该是 DNS 解析出问题了!把 github.com 解析到了本机环回地址,于是产生了屏蔽效果。这种现象被称为“DNS 解析污染”,可能是由于 DNS 解析被运营商劫持了,或者使用了科学上网工具等原因造成的。

一个解决办法是找到 GitHub 服务器的 IP 地址,手动解析。你可以通过 ipaddress.com 网址来找到 IP 地址,或者在终端使用 nslookup 命令查询域名信息。

将正确的IP写入到HOST文件中:c:\Windows\System32\Drivers\etc\ 目录

#4、常用命令

## 重装系统后,本地已经有代码了,从远程中拉取
## 先init
git init
## 设置用户名及邮箱
git config --global user.name "LocoRoco"
git config --global user.email "xxxx@gmail.com"
## 生产pubKey
ssh-keygen -t ed25519 -C "xxxx@gmail.com"
## 到github的settings中设置ssh&GPG-Keys中设置New ssh key

## 强制从远程仓库中拉取并覆盖
git pull git@github.com:xxxx/top-booking.git --allow-unrelated-histories
## 处理完冲突后设置远程仓库
git remote add origin git@github.com:tqsq2005/top-booking.git
## 提交本地新文件
git add .
git commit -m "xxxxx"
git push -u origin master
## 如果上面push不行可执行下面这句
git push git@github.com:xxxx/top-booking.git master