一、遇到的问题:

【1】把代码 push 到 GitHub 过程中遇到的问题:

(py02.py 的代码)

1、第一关:网络根本不通

直接连 GitHub 网络不通,连不上

解决办法:

先检查一下到GitHub是不是通的:

1
curl.exe -I https://github.com

给git配置代理:

1
git config --global http.proxy http://127.0.0.1:7892

查看一下是否配置成功:

1
git config --global --get http.proxy

检查一下从代理服务器到GitHub是不是通的。

1
curl.exe -x http://127.0.0.1:7892 -I https://github.com

查看本机全局git配置:

1
git config --global -l

2、第二关:走了代理,但代理节点不稳

配置了代理之后,Git 到代理软件 到代理节点 到GitHub。

但是代理节点到GitHub那段不稳定,所以会出错。

解决方案:换个节点。。。。。。

3、代理地址写错了一个字母

http写成了HTTPS,改了就好了

1
git config --global http.proxy http://127.0.0.1:7892

二、解决问题中的笔记

【1】Git推送相关

1
2
git push                # 已设置好上游分支后直接用
git push origin main # 明确指定:推到 origin 的 main 分支
1
2
# 查看当前仓库的状态
git status
1
2
# 查看远程仓库的地址,来确定项目连着哪个仓库
git remote -v

【2】Git 代理配置

网络不通时才用。。。。。但是一般都不太通。。。。。

让git的所有网络请求都走本机代理

git 只认 http.proxy 这一条,http 和 https 仓库都走它;https.proxy 是无效配置,不用设!!!(已经犯过错了呜呜呜)

1
git config --global http.proxy http://127.0.0.1:7892

查看配置:

1
2
git config --global --get http.proxy   # 查看某一项
git config --global -l # 列出全部全局配置

取消代理:

1
2
# 取消代理:
git config --global --unset http.proxy

【3】网络连通性测试(排查问题时用)

向目标网站发出请求,只返回响应头,看到 200 OK,说明网络是通的。

1
2
# curl -I 网址
curl -I https://github.com

一个不是很常用的命令:

-x 指定走代理,用来测试代理软件到目标网址是不是通的

1
2
# curl -x 代理地址 -I 网址
curl -x http://127.0.0.1:7892 -I https://github.com

注意!!

Windows 的 power shell 里面,要用 curl.exe

bash 里面直接用 curl

git config –global 代表全局配置,与路径无关

【4】排错思路总结

push失败的时候就可以这样查:

  1. curl -I https://github.com → 直连通不通?
  2. 不通 → 配代理;配了 → curl -x 代理 -I https://github.com → 代理链路通不通?
  3. 代理通但 git 不通 → 检查 git config –global -l,看代理地址是不是写错了(协议、端口)
  4. 看报错信息判断:Failed to connect to 127.0.0.1 = 代理软件没开;Failed to connect to github.com = 没走代理;TLS connect error = 连上了但握手被断(节点不稳,或协议写错)

三、上传博客文章方案

  1. 打开终端,进入 D:\Project\PythonProject\blog

  2. 写文章

    情况1:已经写好了 md 文件:

    把 .md 拖进 source_posts\ 文件夹

    把 文章名.assets 文件夹拖进 source\ 目录

  3. 本地预览

    1
    npx hexo s

    浏览器打开 http://localhost:4000 查看,看完按 Ctrl + C 停止。

  4. 发布方法一:本地部署

    1
    2
    3
    4
    5
    6
    7
    # 部署,更新网站
    npm run deploy

    # 把源码备份到 blog-source 仓库
    git add -A
    git commit -m "更新说明,比如:新文章xxx"
    git push

    直接打开 https://dubingjie.github.io 刷新看

  5. 发布方法二:自动部署

    1
    2
    3
    git add -A
    git commit -m "更新说明,比如:新文章xxx"
    git push

    可以在 https://github.com/dubingjie/blog-source/actions 查看最新一条运行记录

    然后刷新网站即可

差别:

本地 npm run deploy 部署的是电脑上的当前状态——包括还没提交的改动

云端 Actions 部署的只是 push 上去的源码——只认已提交的内容