From 65cd9a80159965ee9fad0c545927b41b00d2b1c4 Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Sat, 13 Sep 2025 15:50:22 +0800 Subject: [PATCH 1/3] docs(git.md): fix some typo & add pre-push hook --- docs/source/development/git.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/source/development/git.md b/docs/source/development/git.md index 93c39f4..b885548 100644 --- a/docs/source/development/git.md +++ b/docs/source/development/git.md @@ -192,7 +192,7 @@ git fetch origin --tags 2. 对于每一个冲突文件,使用 --theirs 选项来检出 main 的版本。 :::{note} - - 在合并操作中,--theirs 代表要合并进来的分支(即 dev/matmaster)的版本。 + - 在合并操作中,--theirs 代表要合并进来的分支(即 main)的版本。 - --ours 代表当前所在的分支(即 test)的版本。 ::: @@ -333,7 +333,7 @@ git cz COMMIT_MSG_FILE=$1 # 允许的前缀列表 -PREFIXES="feat|fix|docs|style|refactor|chore|perf|test|ci|revert" +PREFIXES="feat|fix|docs|style|refactor|build|chore|perf|test|ci|revert" # 读取提交消息的第一行 COMMIT_MSG=$(head -n 1 "$COMMIT_MSG_FILE") @@ -353,7 +353,7 @@ chmod +x .git/hooks/commit-msg ### Commit 前操作 -1. 创建 `.git/hooks/commit-msg` 文件: +1. 创建 `.git/hooks/pre-commit` 文件: ```bash #!/bin/bash @@ -384,6 +384,30 @@ exit 0 chmod +x .git/hooks/pre-commit ``` +### 本地保护 main 或 master 分支 + +1. 创建 `.git/hooks/pre-push` + +```bash +#!/bin/bash + +protected_branches=("main" "master") +current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') + +if [[ " ${protected_branches[@]} " =~ " ${current_branch} " ]]; then + echo "ERROR: You are not allowed to push directly to the $current_branch branch. Use a feature branch and create a Pull Request." + exit 1 +fi + +exit 0 +``` + +2. 将这个钩子脚本设置为可执行: + +```bash +chmod +x .git/hooks/pre-push +``` + ## 使用 Git 模版来初始化 hook 钩子 1. **创建一个模板目录:** From 2666b4053ff45e90dc418e2505d3631a6a4d9f59 Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Sat, 13 Sep 2025 15:56:11 +0800 Subject: [PATCH 2/3] docs(conf.py): update copyright year range to include 2025 --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index d327a05..e167e60 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -18,7 +18,7 @@ # -- Project information ----------------------------------------------------- project = 'OnlineNote' -copyright = '2022-2023, Hui Zhou' +copyright = '2022-2025, Hui Zhou' author = 'Hui Zhou' # The full version, including alpha/beta/rc tags From a189a383965d1aee9266502536be1a1c5ad67294 Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Sat, 13 Sep 2025 15:57:44 +0800 Subject: [PATCH 3/3] docs(git.md): add optional step to disable auto push in oco configuration --- docs/source/development/git.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/source/development/git.md b/docs/source/development/git.md index b885548..dfa0285 100644 --- a/docs/source/development/git.md +++ b/docs/source/development/git.md @@ -555,7 +555,13 @@ oco config set OCO_AI_PROVIDER='azure' OCO_MODEL='gpt-4o' oco config set OCO_API_KEY=xxx ``` -3. 使用 oco 命令生成 commit +3. 【可选】关闭自动 push + +```bash +oco config set OCO_GITPUSH=false +``` + +4. 使用 oco 命令生成 commit ```bash git add .