# 进入博客目录
cd /e/MyBlog
# 创建新文章(标题可以用中文)
hexo new "文章标题"
# 编辑文章(用 Typora/VS Code/记事本)
notepad source/_posts/文章标题.md
文章头部格式示例:
title: 文章标题
date: 2026-02-23 13:26:02
tags: [标签1, 标签2]
categories: [分类名]
# ❌ 错误:& 符号导致命令中断
hexo new "Hexo 博客 & 错误解决大全" && notepad source/_posts/Hexo 博客 & 错误解决大全.md
bash: 错误解决大全.md: command not found
# 第一步:创建文章
hexo new "文章标题"
# 第二步:打开编辑
notepad source/_posts/文章标题.md
hexo new "Hexo 博客 & 错误解决大全" && notepad "source/_posts/Hexo 博客 & 错误解决大全.md"
hexo new "hexo-complete-manual" && notepad source/_posts/hexo-complete-manual.md
# 查看刚创建的文件
ls -l source/_posts/
# 直接用文件名打开(注意用引号)
notepad "source/_posts/文章标题.md"
hexo server
# 或指定端口
hexo s -p 4001
访问 http://localhost:4000 查看效果
按 Ctrl + C 停止预览
# 标准三步曲
hexo clean # 清理缓存
hexo generate # 生成静态文件(可简写为 hexo g)
hexo deploy # 部署到 GitHub(可简写为 hexo d)
# 一键完成
hexo clean && hexo g -d
# 直接编辑源文件
notepad source/_posts/文章标题.md
# 重新部署
hexo clean && hexo g -d
# 删除源文件
rm source/_posts/要删除的文章.md
# 清理并重新部署
hexo clean && hexo g -d
# 创建“关于”页面
hexo new page about
# 创建自定义 HTML 页面
touch source/自定义页面.html
maxkore.bbroot.com)# 进入博客目录
cd /e/MyBlog
# 创建 CNAME 文件(注意:没有扩展名)
echo "你的域名" > source/CNAME
# 验证文件内容
cat source/CNAME
# 应该只显示你的域名,没有多余空格或换行
现象:每次部署后,GitHub Pages 设置里的自定义域名输入框被清空
原因:CNAME 文件缺失、内容错误或未被正确提交
# 1. 检查本地 CNAME 文件
cd /e/MyBlog
cat source/CNAME
# 如果不存在或内容错误,重新创建
# 2. 强制创建正确的 CNAME 文件(-n 参数避免多余换行)
echo -n "maxkore.bbroot.com" > source/CNAME
# 3. 确认内容(应该只有域名,没有额外换行)
cat source/CNAME
# 4. 提交到 Git 仓库
git add source/CNAME
git commit -m "修复 CNAME 文件,确保域名永久生效"
git push
# 5. 重新部署博客
hexo clean && hexo g -d
https://github.com/你的用户名/你的用户名.github.ioCNAME 文件maxkore.bbroot.com)| 可能原因 | 说明 | 解决方法 |
|---|---|---|
| CNAME 文件不存在 | 忘记创建 | echo "域名" > source/CNAME |
| CNAME 文件内容错误 | 有多余空格或换行 | 用 echo -n 重新创建 |
| CNAME 文件没提交 | 只创建没推送 | git add + git commit + git push |
| 文件在错误位置 | 不在 source/ 下 |
移到 source/ 文件夹 |
| GitHub 缓存 | 系统没及时更新 | 手动重新输入保存 |
# 创建完美的 CNAME 文件(一次搞定)
cd /e/MyBlog
echo -n "maxkore.bbroot.com" > source/CNAME
# 添加到 Git 并推送
git add source/CNAME
git commit -m "添加 CNAME 文件,确保自定义域名永久生效"
git push
# 以后每次部署都会自动保留域名
hexo clean && hexo g -d
# 查看当前状态
git status
# 添加所有更改
git add .
# 提交更改
git commit -m "提交说明"
# 推送到 GitHub
git push
# 拉取远程更新
git pull
git add .
git commit -m "更新说明"
git pull origin master
git push origin master
git push -f origin master
错误信息:
YAMLException: can not read a block mapping entry
原因:文章开头的配置格式错误 解决:
检查 : 后面是否有空格
确保缩进正确
示例正确格式:
title: 正确格式 # ✅ 冒号后有空格
tags: [标签] # ✅ 正确
tags: [标签] # ❌ 错误
错误信息:
fatal: unable to access '...': Recv failure: Connection was reset
原因:GitHub 网络波动 解决:
# 方法1:稍后重试
hexo clean && hexo g -d
# 方法2:手动 Git 推送
git add .
git commit -m "更新"
git push
# 方法3:切换网络(WiFi换热点)
错误信息:
! [rejected] master -> master (fetch first)
原因:远程有本地没有的更新 解决:
git pull origin master
git push origin master
错误信息:
Automatic merge failed; fix conflicts and then commit the result.
现象:处于 (master|MERGING) 状态
解决:
# 1. 查看冲突文件
git status
# 2. 添加已解决的文件
git add .
# 3. 完成合并
git commit -m "解决合并冲突"
# 4. 推送
git push origin master
错误信息:
fatal: No url found for submodule path '.deploy_git' in .gitmodules
原因:Git 误将文件夹当作子模块 解决:
# 彻底清理
rm -rf .gitmodules
git rm --cached .deploy_git
git add .
git commit -m "移除子模块配置"
git push
错误信息:
git@github.com: Permission denied (publickey)
原因:SSH 密钥未配置或密码错误 解决:
# 生成新密钥(无密码)
ssh-keygen -t rsa -b 4096 -C "你的邮箱"
# 一直按回车(不设密码)
# 查看公钥
cat ~/.ssh/id_rsa.pub
# 复制公钥添加到 GitHub
# Settings → SSH and GPG keys → New SSH key
错误信息:
remote: Invalid username or token.
原因:Token 错误或过期 解决:
# 重新生成 Token 后使用
git remote set-url origin https://用户名:新token@github.com/用户名/仓库名.git
git push
错误信息:
Error: listen EADDRINUSE
解决:
# 换端口启动
hexo s -p 4001
现象:部署成功但文章没出现 原因:文章头部格式错误 解决:
date 格式是否正确title 不为空hexo clean 后重新生成_config.yml# 网站信息
title: 博客标题
subtitle: 副标题
description: 描述
author: 作者名
language: zh-CN
timezone: Asia/Shanghai
# 部署配置
deploy:
type: git
repo: git@github.com:用户名/用户名.github.io.git
branch: master
themes/next/_config.yml# 菜单
menu:
home: / || fa fa-home
archives: /archives/ || fa fa-archive
tags: /tags/ || fa fa-tags
about: /about/ || fa fa-user
# 头像
avatar:
url: /images/avatar.gif
# 社交链接
social:
GitHub: https://github.com/你的用户名 || fab fa-github
npm updatesource/ 和 _config.ymlsource/CNAME 文件存在且内容正确| 命令 | 作用 | 场景 |
|---|---|---|
hexo new "标题" |
新建文章 | 写作 |
hexo s |
本地预览 | 检查效果 |
hexo clean |
清理缓存 | 解决异常 |
hexo g |
生成静态文件 | 部署前 |
hexo d |
部署 | 上线 |
hexo clean && hexo g -d |
一键部署 | 日常发布 |
git status |
查看状态 | 检查更改 |
git add . |
添加更改 | 提交前 |
git commit -m "说明" |
提交 | 本地记录 |
git push |
推送 | 同步 GitHub |
git pull |
拉取 | 获取更新 |
echo -n "域名" > source/CNAME |
创建 CNAME | 域名配置 |
git pull 确保最新hexo clean 避免缓存问题source/ 文件夹source/ 下放 CNAME 文件| 注意点 | 正确做法 |
|---|---|
标题包含 & 符号 |
用引号括起来,或分步执行 |
| 标题包含空格 | 用引号括起来 |
| 同时打开编辑器 | 分两步执行:先 hexo new,再 notepad |
| 文件名过长 | 用短横线连接,避免特殊字符 |
: 后的空格node_modules/ 到仓库& 等特殊字符不加处理git pullhexo clean && hexo g -dsource/ 文件夹你现在拥有:
从此写博客只需三步:
hexo new "新文章" # 写
hexo clean && hexo g -d # 发
git push # 备(可选)
域名永久保留:
echo -n "你的域名" > source/CNAME # 一次配置,永久有效
创建文章避坑:
# 稳妥的两步法
hexo new "文章标题"
notepad "source/_posts/文章标题.md"