# 🚀 教育投诉平台 Git 仓库迁移指南 ## 📋 **前置检查清单** ✅ 确认已创建新的 Git 仓库(如 GitHub/GitLab) ✅ 备份当前代码到本地压缩文件 ✅ 确认所有重要代码已提交到本地 --- ## 🔧 **步骤 1: 清理旧的 Git 历史** ### 方案 A: 完全重建 Git 仓库(推荐) ```bash # 1️⃣ 进入项目根目录 cd e:\complaint-system # 2️⃣ 删除旧的 Git 仓库 rm -rf .git # 3️⃣ 初始化全新的 Git 仓库 git init # 4️⃣ 添加所有忽略规则生效后的文件 git add . # 5️⃣ 第一次提交 git commit -m "Initial commit: 教育投诉平台源码" # 6️⃣ 重命名主分支为 main(可选) git branch -M main # 7️⃣ 连接到远程仓库 git remote add origin <您的新仓库地址> # 8️⃣ 推送到远程仓库 git push -u --force origin main ``` --- ### 方案 B: 保留历史但清理大文件 如果需要在保持提交历史的同时清理某些文件: ```bash cd e:\complaint-system # 查看所有可能被误提交的文件 git ls-files | grep -E "(reasonix|Demo|doc/)" # 如果要移除特定文件但不删除历史记录 git rm --cached .reasonix/* git rm --cached Demo/* git rm --cached doc/* # 提交更改 git commit -m "Remove non-code files from tracking" # 然后重新关联新仓库 git remote set-url origin <您的新仓库地址> git push -u --force origin main ``` --- ## 🎯 **步骤 2: 验证 Git 忽略配置** ### 检查 `.gitignore` 是否生效 ```bash # 查看未被追踪的文件 git status --ignored # 应该看到以下标记为 'ignored' 的文件/文件夹: # ? ignored/.reasonix/ # ? ignored/Demo/ # ? ignored/doc/ # ? ignored/h5-app/node_modules/ ``` ### 手动测试忽略规则 ```bash # 测试 h5-app 的 node_modules 是否被忽略 cd h5-app ls node_modules # 应该是空输出或显示为 ignored # 返回根目录 cd .. ``` --- ## 🔒 **步骤 3: 确保敏感信息不泄露** ### 检查配置文件中的敏感数据 ```bash # 在 git commit 之前运行以下检查 grep -r "password" --include="*.yml" --include="*.yaml" --include="*.properties" src/ grep -r "secret" --include="*.env*" src/ ``` ### 推荐的敏感信息管理 1. **使用环境变量文件** (不被 Git 追踪): ``` complaint-admin/src/main/resources/application-dev.yml ``` 应包含占位符: ```yaml spring: datasource: username: ${DB_USERNAME} password: ${DB_PASSWORD} url: jdbc:dm://localhost:5236?useSSL=false ``` 2. **本地覆盖配置文件**: 创建 `application-local.yml` 并放入个人配置(加入.gitignore): ```yaml # 本地开发配置 spring: datasource: username: admin password: your_password_here ``` --- ## 📝 **步骤 4: 推送前最终检查** ```bash # 1. 查看即将提交的所有文件 git status # 2. 确认未包含的文件 git check-ignore -v .reasonix/ git check-ignore -v Demo/ git check-ignore -v doc/ git check-ignore -v h5-app/node_modules/ # 预期输出: # ignore:.reasonix/ # ignore:Demo/ # ignore:doc/ # ignore:h5-app/node_modules/ ``` --- ## 🌟 **步骤 5: 推送到远程仓库** ### 连接到新仓库 ```bash # 替换为您的实际仓库地址 git remote add origin git@github.com:your-username/complaint-system.git # 或者 HTTPS 方式 # git remote add origin https://github.com/your-username/complaint-system.git # 推送 git push -u origin main # 如果是首次推送到私有仓库 git push -u origin main --force ``` --- ## ✅ **验证列表** 推送后,请在新克隆的仓库中验证: ```bash # 1. 全新克隆(在其他机器上) git clone <您的仓库地址> cd complaint-system # 2. 确认不包含以下文件 ls .reasonix # ❌ 应该不存在 ls Demo # ❌ 应该不存在 ls doc/ # ❌ 应该不存在 ls h5-app/node_modules/ # ❌ 应该不存在 # 3. 确认核心文件存在 ls pom.xml # ✅ ls h5-app/package.json # ✅ ls ruoyi-ui/package.json # ✅ ``` --- ## 🛠️ **常见问题的解决方案** ### Q1: Git 提示文件已缓存,无法被忽略? ```bash # 强制从缓存中移除文件 git rm --cached -r .reasonix/ git rm --cached -r Demo/ git rm --cached -r doc/ # 重新提交 git commit -m "Update gitignore to exclude non-code files" ``` ### Q2: 不小心提交了大文件怎么办? ```bash # 使用 git-filter-repo 工具(推荐) pip install git-filter-repo git filter-repo --path .reasonix/ --invert-paths git filter-repo --path Demo/ --invert-paths # 或者手动清理历史 git filter-branch --prune-empty --path .reasonix/ HEAD~10..HEAD ``` ### Q3: 多个前端项目的 node_modules 导致仓库过大? ```bash # 使用 git-lfs(可选) # 如果必须存储某些构建产物,可以使用 LFS git lfs install git lfs track "*.lock" # 但推荐完全不追踪 node_modules echo "node_modules/" >> .gitignore git rm -r --cached node_modules/ ``` --- ## 📊 **推荐的项目结构** 成功迁移后的项目树(`.gitignore` 生效状态): ``` complaint-system/ ├── .gitignore ✅ ├── pom.xml ✅ ├── sql/ ✅ (数据库脚本) ├── complaint-admin/ ✅ ├── complaint-common/ ✅ ├── complaint-workorder/ ✅ ├── ruoyi-ui/ │ ├── node_modules/ ❌ (被忽略) │ ├── .gitignore ✅ │ └── src/ ✅ ├── h5-app/ │ ├── node_modules/ ❌ (被忽略) │ ├── .gitignore ✅ │ └── src/ ✅ ├── Demo/ ❌ (被忽略) ├── reasonix/ ❌ (被忽略) ├── doc/ ❌ (被忽略) └── ...其他源代码 ✅ ``` --- ## 🎯 **最后一步:创建 README** 建议添加项目说明: ```markdown # 教育投诉平台 ## 技术架构 - 后端:Spring Boot + MyBatis + 达梦数据库 - PC 前端:Vue3 + Element Plus + Vite - H5 前端:Vue3 + Vant ## 快速开始 ```bash # 启动后端 ./ry.sh start # 启动 PC 前端 cd ruoyi-ui && npm run dev # 启动 H5 前端 cd h5-app && npm run dev ``` ## 注意事项 - `node_modules/` 不会被 Git 追踪 - 数据库配置请在本地 `application-local.yml` 中设置 - 详见 SQL 文档和开发规范文档 ``` --- ## 📞 **需要帮助?** 如果遇到任何 Git 相关问题,请提供: ```bash # 获取调试信息 git version git config --global --list git remote -v ``` 祝您的项目顺利迁移到新仓库!🎉