You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
slms/docs/GIT_REPOSITORY_SETUP_GUIDE.md

4.1 KiB

Git 仓库设置指南

目的: 将重构后的项目推送到本地 Gitea 和头歌仓库


前提条件

1. Gitea 服务运行

确保 Gitea 服务正在运行:

# 访问 Gitea
http://localhost:3000

2. 在 Gitea 中创建仓库

  1. 访问: http://localhost:3000
  2. 登录 Gitea
  3. 点击右上角 +New Repository
  4. 填写信息:
    • Repository Name: slms
    • Visibility: Private 或 Public
    • 不要 初始化 README、.gitignore 或 License
  5. 点击 Create Repository

3. 配置 Git 凭据(可选)

如果需要避免每次输入密码:

方法 1: 使用凭据管理器

git config --global credential.helper wincred

方法 2: 使用 SSH 密钥

  1. 生成 SSH 密钥: ssh-keygen -t rsa -b 4096
  2. 在 Gitea 中添加公钥: Settings → SSH/GPG Keys
  3. 使用 SSH URL: git@localhost:gitea/slms.git

方法 1: 使用自动化脚本(推荐)

步骤 1: 运行设置脚本

scripts\setup_git_repository.bat

脚本将自动:

  1. 检查或初始化 Git 仓库
  2. 添加所有文件
  3. 创建初始提交
  4. 配置远程仓库
  5. 推送到 Gitea

步骤 2: 验证推送

访问 Gitea 仓库页面:

http://localhost:3000/gitea/slms

检查文件是否已上传。


方法 2: 手动执行命令

步骤 1: 初始化 Git 仓库(如果需要)

# 检查是否已有 Git 仓库
git status

# 如果没有,初始化
git init

步骤 2: 配置 Git 用户信息

git config user.name "Your Name"
git config user.email "your.email@example.com"

步骤 3: 添加所有文件

git add .

步骤 4: 创建初始提交

git commit -m "Initial commit: SLMS project restructure"

步骤 5: 添加远程仓库

# 添加本地 Gitea
git remote add origin http://localhost:3000/gitea/slms.git

# 如果已存在,更新 URL
git remote set-url origin http://localhost:3000/gitea/slms.git

步骤 6: 推送到 Gitea

# 强制推送到 main 分支
git push -u origin main --force

注意: --force 会覆盖远程仓库内容,请谨慎使用!


验证推送

1. 检查远程仓库

git remote -v

应该显示:

origin  http://localhost:3000/gitea/slms.git (fetch)
origin  http://localhost:3000/gitea/slms.git (push)

2. 检查最新提交

git log -1

3. 访问 Gitea Web 界面

访问: http://localhost:3000/gitea/slms

检查:

  • 所有文件已上传
  • 提交历史正确
  • 分支为 main

常见问题

Q1: 推送时要求输入用户名和密码

A:

  1. 输入 Gitea 的用户名和密码
  2. 或配置凭据管理器: git config --global credential.helper wincred
  3. 或使用 SSH 密钥

Q2: 推送失败 - 仓库不存在

A:

  1. 确认 Gitea 服务正在运行
  2. 在 Gitea 中创建仓库 slms
  3. 确保仓库 URL 正确

Q3: 推送失败 - 认证失败

A:

  1. 检查用户名和密码是否正确
  2. 检查用户是否有推送权限
  3. 尝试使用 SSH 密钥

Q4: 推送失败 - 网络错误

A:

  1. 检查 Gitea 服务是否运行: http://localhost:3000
  2. 检查防火墙设置
  3. 尝试使用 127.0.0.1 代替 localhost

Q5: 文件太大无法推送

A:

  1. 检查 .gitignore 是否正确配置
  2. 移除大文件: git rm --cached large-file
  3. 配置 Git LFS: git lfs install

.gitignore 配置

确保以下文件/目录被忽略:

# 构建产物
target/
build/
*.apk
*.jar
*.war
*.exe
*.msi

# IDE 文件
.idea/
.vscode/
*.iml

# 依赖
node_modules/
.gradle/

# 临时文件
*.log
*.tmp
.DS_Store
Thumbs.db

# 备份
backup_*/

下一步

完成本地 Gitea 推送后:

  1. 配置头歌远程仓库(任务 18
  2. 更新 Jenkins 配置(任务 19
  3. 测试完整流水线(任务 20

相关脚本:

  • scripts/setup_git_repository.bat - 自动化设置脚本
  • scripts/push_to_educoder.bat - 推送到头歌(任务 18

相关文档:

  • .kiro/specs/repository-restructure/design.md
  • Jenkinsfile (已更新)