管理博客源码


正确操作步骤

  1. 确保 .gitignore 文件正确
    Hexo 初始化时通常会自动生成 .gitignore,其中会忽略 public/node_modules/ 等目录。检查你的 .gitignore 是否包含以下内容:

    1
    2
    3
    /public
    /node_modules
    /.deploy_git
  2. 切换到新分支 hexo-source

    1
    git checkout -b hexo-source
  3. 提交源码(无需删除任何内容)
    直接提交 Hexo 项目文件(不包括被 .gitignore 忽略的文件):

    1
    2
    3
    git add .
    git commit -m "初始化 Hexo 源码"
    git push origin hexo-source
  4. 后续更新流程

    • 写新文章后,先推送到 hexo-source 分支:
      1
      2
      3
      git add .
      git commit -m "更新文章:xxx"
      git push origin hexo-source
    • 再部署静态文件到 main/master 分支:
      1
      hexo clean && hexo g -d

为什么不需要删除分支内容?

  • Hexo 的 deploy 命令(hexo-deployer-git)会自动将 public/ 下的静态文件推送到 main/master 分支,与 hexo-source 分支完全隔离。
  • hexo-source 分支仅保存源码(如 Markdown 文章、主题配置等),而 GitHub Pages 只会读取 main/master 分支的静态文件。

注意事项

  1. 不要手动删除 hexo-source 分支的文件
    如果误删了 _config.ymlthemes/ 等关键文件,会导致本地无法生成静态文件。

  2. 首次部署前确保 main/master 分支为空

    • 如果 main/master 分支已有内容(如 GitHub 自动生成的 README.md),建议先清空该分支,否则部署可能冲突。
    • 清空方法:
      1
      2
      3
      4
      5
      git checkout --orphan temp-branch
      git commit -m "初始化空分支"
      git branch -D main # 删除本地 main 分支
      git branch -m main # 重命名当前分支为 main
      git push -f origin main
  3. 区分两个分支的作用

    • hexo-source:存储源码(你本地编辑的文件)。
    • main/master:存储 Hexo 生成的静态文件(自动由 hexo deploy 推送)。

总结

  • 不需要 手动删除 hexo-source 分支的内容,直接提交即可。
  • 保持 .gitignore 正确,避免提交 public/ 等无关文件。
  • 两个分支互不干扰:源码在 hexo-source,静态页面在 main/master

管理博客源码
hhttps://www.fengyu-blog.top/2025/05/10/管理博客源码/
作者
风语
发布于
2025年5月10日
许可协议