✅ 第一步:检查是否安装 Git

打开命令提示符(Win+R 输入 cmd),然后输入以下命令:

1
2
3
4
5
bash


复制编辑
git --version

预期结果:
你应该看到类似这样的输出:

1
2
3
4
5
nginx


复制编辑
git version 2.39.1.windows.1

🔄 如果出现 'git' 不是内部或外部命令

说明 Git 没有安装,或者没有添加到系统环境变量。请:

  1. 下载安装 Git:https://git-scm.com/downloads
  2. 安装时选择 将 Git 添加到 PATH(默认勾选)
  3. 安装完成后,重新打开终端再试一次 git --version

✅ 第二步:检查是否安装 hexo-deployer-git 插件

在你的 Hexo 项目的根目录(例如 F:\Myblog)打开命令行,输入以下命令:

1
2
3
4
5
bash


复制编辑
npm ls hexo-deployer-git

如果显示插件信息(比如版本号),说明已经安装;如果提示 empty 或报错,说明没有安装。


🔧 如果未安装或不确定,请执行安装命令:

1
2
3
4
5
bash


复制编辑
npm install hexo-deployer-git --save

安装完成后,重新尝试部署命令:

1
2
3
4
5
bash


复制编辑
hexo clean && hexo deploy

很好,说明你已经成功安装了 hexo-deployer-git 插件 ✅。

接下来我们继续检查:


✅ 第三步:检查 _config.yml 中的部署配置

请用编辑器打开你 Hexo 项目的根目录下的 _config.yml 文件(不是 themes 文件夹里的),找到以下部分:

1
2
3
4
yaml复制编辑deploy:
type: git
repo: https://github.com/你的用户名/你的仓库名.git
branch: main # 或者 master,看你的仓库是哪个分支

☑️ 请确认以下几点:

  • type: git 是正确的。
  • repo: 是你的 Git 仓库地址(比如 GitHub 仓库的 HTTPS 或 SSH 链接)。
  • branch: 是你的远程仓库用于部署的分支,一般是 mainmaster
  • 注意缩进要对齐(YAML 文件对空格非常敏感)。

✅ 示例配置(以 GitHub 为例):

1
2
3
4
yaml复制编辑deploy:
type: git
repo: https://github.com/yourname/yourrepo.git
branch: main

或者使用 SSH(需配置过 SSH key):

1
2
3
4
yaml复制编辑deploy:
type: git
repo: git@github.com:yourname/yourrepo.git
branch: main

deploy: type: git repository: git@github.com:QvQ-Ling/QvQ-Ling.github.io.git branch: master Plugins: - hexo-generator-cname

你的配置基本正确,但有一个关键错误导致 Hexo 无法识别部署设置:


✅ 正确写法应该是:

1
2
3
4
5
6
7
deploy:
type: git
repo: git@github.com:QvQ-Ling/QvQ-Ling.github.io.git
branch: master

plugins:
- hexo-generator-cname

🔄 修改后,重新部署试试:

1
2
3
hexo clean
hexo generate
hexo deploy
您说:

FATAL Something’s wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html Error: Spawn failed at ChildProcess. (F:\Myblog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21) at ChildProcess.emit (node:events:507:28) at cp.emit (F:\Myblog\node_modules\cross-spawn\lib\enoent.js:34:29) at ChildProcess._handle.onexit (node:internal/child_process:294:12)

你已经修正了配置文件,但仍然遇到 Spawn failed 错误,这说明 Hexo 启动了一个子进程(通常是调用 Git),但是失败了。这通常是以下几种情况之一:


✅ 第四步:确认 SSH 配置是否正常

你使用的是 SSH 格式的仓库地址

1
git@github.com:QvQ-Ling/QvQ-Ling.github.io.git

所以你需要确认你的电脑是否配置好了 GitHub 的 SSH key。


🧪 测试 SSH 是否可用:

在命令行输入以下命令:

1
ssh -T git@github.com

正常输出应该是:

1
Hi QvQ-Ling! You've successfully authenticated, but GitHub does not provide shell access.

如果提示 “Permission denied (publickey)”:

说明你没有配置 SSH key 或 key 没有添加到 GitHub。

✅ 解决方法:

  1. 生成 SSH key(如果还没有):
1
ssh-keygen -t rsa -C "your_email@example.com"

一路回车即可。

  1. 查看公钥:
1
type %userprofile%\.ssh\id_rsa.pub
  1. 复制输出内容,添加到 GitHub:
    • 打开 GitHub → 设置(Settings)→ SSH and GPG keys → 新建 SSH key
    • 粘贴进去并保存
  2. 添加 key 到当前终端:
1
ssh-add %userprofile%\.ssh\id_rsa
报错:

ssh: connect to host github.com port 22: Connection timed out

这个错误说明你当前网络无法连接 GitHub 的默认 SSH 端口(22)。这在中国大陆很常见,通常是由于防火墙或运营商屏蔽了 SSH 的 22 端口。


✅ 解决方案:改用 GitHub 的 端口 443 SSH

你可以配置 Git 使用 端口 443 的 SSH 地址,避开被屏蔽的 22 端口。

1. 修改 SSH 配置文件

打开或创建 ~/.ssh/config 文件(在 Windows 上是 C:\Users\你的用户名\.ssh\config),加入以下内容:

1
2
3
4
sql复制编辑Host github.com
Hostname ssh.github.com
Port 443
User git

你可以用记事本或 VS Code 打开这个文件,没有的话就新建一个。


2. 测试 SSH 是否连通:

1
2
3
4
5
bash


复制编辑
ssh -T git@github.com

如果配置成功,应该看到:

1
Hi QvQ-Ling! You've successfully authenticated...

这说明你的 SSH 连接已经配置好,网络问题也已经解决 ✅。


✅ 最后一步:重新部署 Hexo 博客

现在回到你的 Hexo 项目目录

然后依次执行以下命令:

1
2
3
hexo clean
hexo generate
hexo deploy