确保你已经:
- ✅ 清理了项目(删除 demo 文件夹和临时文档)
- ✅ 更新了配置文件
- ✅ 创建了 GitHub 仓库: https://github.com/lucas8848168/Calorie-AnalysisDEMO.git
# 如果已有 .git 文件夹,先删除旧的
rm -rf .git
# 初始化新的 Git 仓库
git initgit remote add origin https://github.com/lucas8848168/Calorie-AnalysisDEMO.git# 添加所有文件
git add .
# 或者选择性添加
git add src/ functions/ public/ .github/
git add package.json vite.config.ts tsconfig.json
git add README.md DEPLOYMENT.md PROJECT_SUMMARY.md
git add .env.example .gitignore .prettierrcgit commit -m "Initial commit: Food Calorie Analyzer DEMO v2.0"# 推送到 main 分支
git branch -M main
git push -u origin main推送成功后:
-
查看仓库
- 访问 https://github.com/lucas8848168/Calorie-AnalysisDEMO
- 确认所有文件已上传
-
检查 GitHub Actions
- 进入 Actions 标签
- 查看自动部署是否触发
- 等待构建完成(约 2-3 分钟)
-
启用 GitHub Pages
- 进入 Settings → Pages
- Source 选择 "GitHub Actions"
- 保存设置
-
访问网站
- 部署完成后访问: https://lucas8848168.github.io/Calorie-AnalysisDEMO/
- 测试功能是否正常
确保以下内容在 .gitignore 中:
# 依赖
node_modules/
# 构建输出
dist/
.wrangler/
# 环境变量
.env
.env.local
.env.*.local
.dev.vars
# 日志
logs/
*.log
# 系统文件
.DS_Store
Thumbs.db
# IDE
.vscode/
.idea/
# 临时文件
*.tmp
*.temp
重要: 不要提交敏感信息!
-
本地开发
- 使用
.env文件(已在 .gitignore 中) - 提交
.env.example作为模板
- 使用
-
生产环境
- 在 Cloudflare Pages Dashboard 配置
- 不要在代码中硬编码 API 密钥
# 1. 修改代码
# 2. 测试功能
npm run dev
# 3. 构建验证
npm run build
# 4. 提交更改
git add .
git commit -m "描述你的更改"
# 5. 推送到 GitHub
git push origin main# 创建并切换到新分支
git checkout -b feature/new-feature
# 开发完成后推送
git push origin feature/new-feature
# 在 GitHub 上创建 Pull RequestA: 检查 GitHub 认证:
# 使用 HTTPS(需要 Personal Access Token)
git remote set-url origin https://github.com/lucas8848168/Calorie-AnalysisDEMO.git
# 或使用 SSH
git remote set-url origin git@github.com:lucas8848168/Calorie-AnalysisDEMO.gitA: 先拉取远程更改:
git pull origin main --rebase
git push origin mainA: 立即从历史中删除:
# 删除文件并从历史中移除
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch .env" \
--prune-empty --tag-name-filter cat -- --all
# 强制推送
git push origin --force --allA:
# 查看提交日志
git log --oneline
# 查看详细信息
git log --stat
# 图形化查看
git log --graph --oneline --all推送前检查:
- 删除了 demo-frontend-only 文件夹
- 删除了所有临时文档
- 更新了 vite.config.ts 中的 base path
- 更新了 package.json 中的仓库信息
- 创建了 GitHub Actions 配置
- 更新了 README.md
- 创建了 DEPLOYMENT.md
- 检查了 .gitignore
- 没有提交 .env 文件
- 本地构建成功 (
npm run build) - 本地测试通过 (
npm run dev)
推送成功后,你的项目将:
- ✅ 托管在 GitHub
- ✅ 自动部署到 GitHub Pages
- ✅ 可以通过 URL 访问
- ✅ 支持持续集成/部署
祝你部署顺利! 🚀