Hexo 常用命令速查手册

Hexo 基础命令

安装与初始化

1
2
3
4
5
6
7
8
# 全局安装 Hexo CLI
npm install hexo-cli -g

# 初始化项目
hexo init <folder>

# 安装依赖
npm install

开发与预览

1
2
3
4
5
6
7
8
9
10
11
# 生成静态文件
hexo generate

# 启动开发服务器
hexo server

# 启动服务器并指定端口
hexo server -p 4000

# 生成并启动预览
hexo g && hexo s

部署

1
2
3
4
5
6
7
8
# 安装部署插件
npm install hexo-deployer-git --save

# 一键部署
hexo clean && hexo generate && hexo deploy

# 简写命令
hexo d

Git 配置指南

全局配置

1
2
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

SSH 密钥生成

1
2
3
4
5
6
7
8
# 生成密钥
ssh-keygen -t rsa -C "your_email@example.com"

# 查看公钥
cat ~/.ssh/id_rsa.pub

# 测试连接
ssh -T git@github.com

远程仓库管理

1
2
3
4
5
6
7
8
9
10
11
# 查看远程仓库
git remote -v

# 添加远程仓库
git remote add origin https://github.com/username/repo.git

# 删除远程仓库
git remote rm origin

# 修改远程仓库地址
git remote set-url origin https://github.com/username/repo.git

提交代码

1
2
3
4
5
6
7
8
# 添加所有文件
git add .

# 提交更改
git commit -m "commit message"

# 推送到远程
git push origin main

Hexo 部署配置

编辑 _config.yml

1
2
3
4
deploy:
type: git
repo: https://github.com/YourName/YourName.github.io.git
branch: main

.gitignore 配置

1
2
3
4
5
6
7
.DS_Store
Thumbs.db
db.json
*.log
node_modules/
public/
.deploy*/

常见问题

恢复 Hexo 项目

1
2
3
4
git clone <repo-url>
cd <repo-name>
npm install
npm install hexo-deployer-git --save

强制推送

1
git push -f origin main

修改分支名称

1
git branch -m main

这份手册涵盖了 Hexo 日常开发和部署的所有常用命令,建议收藏备用!


Hexo 常用命令速查手册
https://blog.15xd.cn/posts/fsfg1641.html
作者
周次辉
发布于
2022年6月17日
许可协议