Hugo 博客的正确 Git 提交流程

前言 在使用 Hugo 搭建博客并部署到 Cloudflare Pages 时,正确的 Git 提交流程很重要。本文记录了如何避免提交不必要的构建文件,保持仓库整洁。 问题背景 Hugo 会将源文件(content/)编译成静态 HTML 文件输出到 public/ 目录。这些构建产物不应该提交到 Git 仓库,因为: 文件体积大:每次构建都会生成大量 HTML、CSS、JS 文件 频繁变动:每次修改都会重新生成,造成大量无意义的 diff 自动构建:Cloudflare Pages 会自动执行构建,不需要提交构建产物 污染历史:会让 Git 历史变得混乱,难以追踪真正的内容变更 配置 .gitignore 首先创建 .gitignore 文件,排除构建输出和临时文件: # Hugo build output public/ resources/ # Hugo lock file .hugo_build.lock # IDE .vscode/ .idea/ *.swp *.swo *~ # OS .DS_Store Thumbs.db # Node modules (if using npm for theme development) node_modules/ # Temporary files *.log *.tmp 标准提交流程 1. 创建或编辑内容 1 2 3 4 5 # 创建新文章 hugo new posts/my-new-post.md # 或直接编辑现有文章 # vim content/posts/existing-post.md 2. 本地预览(可选但推荐) 1 2 3 4 5 # 启动开发服务器,-D 参数显示草稿 hugo server -D # 浏览器访问 http://localhost:1313 预览效果 # 确认无误后 Ctrl+C 停止服务器 3. 提交源文件到 Git 1 2 3 4 5 6 7 8 9 10 11 12 13 14 # 查看修改了哪些文件 git status # 添加要提交的文件 git add content/posts/my-new-post.md # 或一次添加所有修改(.gitignore 会自动排除构建文件) git add . # 提交,使用清晰的提交信息 git commit -m "feat: 添加新文章《文章标题》" # 推送到远程仓库 git push origin main 4. 自动部署 推送后,Cloudflare Pages 会自动: ...

August 21, 2026 · 2 min · 418 words · Wang

我的第一篇博客

你好,世界! 这是我用 Hugo + Cloudflare Pages 搭建的个人博客。

August 19, 2026 · 1 min · 7 words · Wang