Files
a-share-analysis/docs/governance/version-control-and-gitea.md
T

3.0 KiB

Git 与 Gitea 规范

1. 当前策略

本项目使用本地 Git 和用户自建 Gitea,不使用 GitHub,也不创建 GitHub Actions。

配置项
Gitea 基础地址 https://git.foximao.com/
项目账号 FoXiMao
唯一远程仓库 https://git.foximao.com/FoXiMao/a-share-analysis.git
远程名 origin
配置作用域 当前项目 .git/config

密码不属于项目文档。它不得出现在仓库文件、Git 历史、远程 URL、脚本或命令参数中;首次认证时由 Git 凭据助手请求,并交由 macOS Keychain 保存。

2. 分支与提交

  • main 始终保持可验证和可回退。
  • 普通功能使用 feature/<功能编号>-<短名称>
  • 修复使用 fix/<功能编号>-<短名称>
  • 提交必须符合中文 Conventional Commit,仓库通过 .githooks/commit-msg检查。
  • 禁止强推共享 main,禁止使用破坏历史的回退方式处理已共享版本。

首次克隆后执行:

git config core.hooksPath .githooks

3. Gitea 项目级接入

在本项目根目录执行以下项目级配置:

git remote add origin https://git.foximao.com/FoXiMao/a-share-analysis.git
git config --local credential.helper osxkeychain
git config --local credential.useHttpPath true
git config --local credential.username FoXiMao
git config --local remote.pushDefault origin

credential.useHttpPath=true 让同一 Gitea 域名下不同仓库按路径区分凭据;所有设置使用 --local,只写入本项目不可提交的 .git/config。禁止使用 git config --global 配置本项目账号、凭据助手或默认推送目标。

只读连通性检查:

GIT_TERMINAL_PROMPT=0 git ls-remote origin

首次需要写权限时,由用户在交互式终端执行推送并输入凭据:

git push -u origin main

添加远程和验证连通性不代表授权自动推送。代理只有在用户明确要求推送时才能执行。建议在 Gitea 中保护 main:禁止强推、要求状态检查通过、要求变更说明关联功能编号。

4. 配置检查与移除

检查当前项目和全局配置的边界:

git remote -v
git config --local --get credential.helper
git config --local --get credential.useHttpPath
git config --global --get-all credential.helper
git config --global --get remote.pushDefault

如需解除本项目 Gitea 接入,执行:

git remote remove origin
git config --local --unset credential.helper
git config --local --unset credential.useHttpPath
git config --local --unset credential.username
git config --local --unset remote.pushDefault

上述操作只影响本项目。Keychain 中已保存的凭据需要在“钥匙串访问”中按 git.foximao.com 单独删除。

5. 版本与标签

发布使用带注释标签,例如:

git tag -a v0.1.0 -m "发布市场综合概览 v0.1.0"

标签必须指向通过验证的提交。应用回退优先选择既有标签和不可变构建产物,而不是重新拼装旧版本。