整理文件路径:Technical→AI/
This commit is contained in:
114
raw/Home Office/Git Push 连接重置问题修复.md
Normal file
114
raw/Home Office/Git Push 连接重置问题修复.md
Normal file
@@ -0,0 +1,114 @@
|
||||
---
|
||||
title: 输出可能为: origin https://github.com/ishenwei/tiktok_pm.git (fetch)
|
||||
source:
|
||||
author: shenwei
|
||||
published:
|
||||
created:
|
||||
description:
|
||||
tags: [github, proxy, push, socks5]
|
||||
---
|
||||
|
||||
#github #push #proxy #socks5
|
||||
|
||||
|
||||
这是一个典型的**网络连接干扰**问题,特别是在国内访问 GitHub 时非常常见。
|
||||
|
||||
### 核心原因分析
|
||||
|
||||
`Recv failure: Connection was reset`(连接重置)并不是账号权限验证失败,而是 **TCP 连接层面的中断**。
|
||||
|
||||
- **现象:** 客户端尝试与 GitHub 服务器建立安全连接(TLS Handshake),但中间的网络防火墙(GFW)检测到了流量特征或目标域名,强行发送了 TCP RST 包阻断连接。
|
||||
|
||||
- **为何间歇性:** GitHub 的 CDN 节点众多,部分 IP 被封锁,部分未被封锁;或者是干扰策略存在由于流量负载导致的“漏网之鱼”。
|
||||
|
||||
|
||||
### 解决方案
|
||||
|
||||
最有效、最根本的解决方案是让 Git 的流量走你本地的代理通道(既然你之前提到过使用 V2RayN,这是最直接的利用方式)。
|
||||
|
||||
#### 方法一:为 Git 单独配置代理(推荐)
|
||||
|
||||
这种方法只会影响 Git 命令,不会干扰终端里其他命令的网络请求。
|
||||
|
||||
假设你的代理软件(如 V2RayN, Clash 等)本地监听端口如下(请根据你实际设置修改端口号):
|
||||
|
||||
- HTTP/HTTPS 代理端口:`10809`
|
||||
|
||||
- SOCKS5 代理端口:`10808`
|
||||
|
||||
|
||||
**1. 设置 HTTP 代理(最通用)** 在终端(Terminal 或 PowerShell)执行:
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
git config --global http.proxy http://127.0.0.1:10809
|
||||
git config --global https.proxy http://127.0.0.1:10809
|
||||
```
|
||||
|
||||
_注意:即使是访问 `https://`,配置项名称也是 `https.proxy`,但代理协议通常写 `http://` 即可,除非你的代理明确要求 https。_
|
||||
|
||||
**2. 设置 SOCKS5 代理(速度通常更快)** 如果你想走 SOCKS5 协议:
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
git config --global http.proxy socks5://127.0.0.1:10808
|
||||
git config --global https.proxy socks5://127.0.0.1:10808
|
||||
```
|
||||
|
||||
**验证配置是否生效:**
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
git config --global --get http.proxy
|
||||
```
|
||||
|
||||
**如何取消代理:** 如果你切换了网络环境(例如到了国外),不再需要代理,可以使用以下命令取消:
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
git config --global --unset http.proxy
|
||||
git config --global --unset https.proxy
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 方法二:从 HTTPS 切换到 SSH 协议
|
||||
|
||||
有时候 HTTPS 的 443 端口干扰严重,但 SSH 的 22 端口相对稳定(或者反过来)。你可以尝试更改远程仓库地址。
|
||||
|
||||
**1. 查看当前远程地址**
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
git remote -v
|
||||
# 输出可能为: origin https://github.com/ishenwei/tiktok_pm.git (fetch)
|
||||
```
|
||||
|
||||
**2. 修改为 SSH 地址**
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
git remote set-url origin git@github.com:ishenwei/tiktok_pm.git
|
||||
```
|
||||
|
||||
_前提:你必须已经生成了 SSH Key (`ssh-keygen`) 并将公钥上传到了 GitHub Settings 中。_
|
||||
|
||||
**进阶:如果 SSH 直连也不稳** 可以通过修改 `~/.ssh/config` (Linux/Mac) 或 `C:\Users\你的用户名\.ssh\config` (Windows),让 SSH 连接也走代理:
|
||||
|
||||
Plaintext
|
||||
|
||||
```
|
||||
Host github.com
|
||||
User git
|
||||
Hostname github.com
|
||||
# Windows 下使用 connect.exe (Git自带)
|
||||
ProxyCommand connect -S 127.0.0.1:10808 %h %p
|
||||
# Linux/Mac 下使用 ncat (需安装 netcat)
|
||||
# ProxyCommand nc -X 5 -x 127.0.0.1:10808 %h %p
|
||||
```
|
||||
Reference in New Issue
Block a user