在搭建个人博客网站时所遇到的问题。

问题-1:VS Code 无法检测到 Git Bash

在Microsoft Visual Studio Code 的终端下拉列表中,没有找到 Git Bash 选项,只能使用默认的 PowerShell。
已经尝试对terminal.integrated.profiles.windows中的 Git 安装路径(bash.exe)进行手动设置,未能解决。

解决方法

重新安装Git,直接将其安装在C盘。

问题-2: 部署时报错 Spawn failed / Port 443

在执行 hexo -d 部署时,出现以下报错:

1
2
3
4
5
6
7
8

fatal: unable to access 'https://github.com/Hai-Jun-Yan/Blog_haijun/': Failed to connect to github.com port 443 after 21051 ms: Could not connect to server
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: Spawn failed
at ChildProcess.<anonymous> (D:\Blog_haijun\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (node:events:508:28)
at cp.emit (D:\Blog_haijun\node_modules\cross-spawn\lib\enoent.js:34:29)
at ChildProcess._handle.onexit (node:internal/child_process:294:12)

解决方法

git bash终端使用管理员权限打开

问题-3:连接被重置 (Connection was reset)

解决了权限问题后,再次推送时出现网络连接错误:

1
fatal: unable to access 'https://github.com/Hai-Jun-Yan/Blog_haijun/': Recv failure: Connection was reset

原因分析

这是由于国内网络环境访问 GitHub 不稳定导致的。需要为 Git 配置本地代理(前提是电脑上开启了代理软件,且端口号可以在clash里面看到,这次正正好是7890)。

解决方法

在终端执行以下命令设置 Git 代理:

1
2
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

问题-4

在使用 hexo -d 将博客部署到 GitHub 后,发现 GitHub 仓库主页没有显示 README.md 文件,而是直接显示了网页文件列表。

原因分析

Hexo 部署时会将 source 目录下的 Markdown 文件渲染成 HTML。如果 README.md 放在根目录,不会被打包;如果放在 source 目录且未配置跳过渲染,会被转换成 HTML,导致 GitHub 无法识别。

解决方法

1. 移动文件

README.md 文件移动到 source 目录下(注意:不要放在 source/_posts 里)。

2. 修改配置

修改博客根目录下的 _config.yml 文件,添加跳过渲染配置:

1
skip_render: README.md