Skip to content

Commit cb20162

Browse files
committed
docs: Update Git hook documentation 📖
Signed-off-by: mingcheng <mingcheng@apache.org>
1 parent cb2a9fe commit cb20162

1 file changed

Lines changed: 28 additions & 26 deletions

File tree

README.md

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,59 +114,61 @@ Note: Use `--yes` to skip interactive confirmations in non-TTY environments.
114114

115115
### Git Hook
116116

117-
AIGitCommit includes a `prepare-commit-msg` hook that automatically generates commit messages during your workflow. The hook triggers when you run `git commit` or `git commit -m ""`, generates a message from staged changes, and opens your editor for review.
117+
AIGitCommit includes a `prepare-commit-msg` hook that automatically generates commit messages during your workflow.
118+
119+
**Quick install (recommended)**
120+
121+
Install into the current repository:
122+
123+
```bash
124+
aigitcommit install-hook .
125+
```
126+
127+
Install into a specific repository:
128+
129+
```bash
130+
aigitcommit install-hook /path/to/repo
131+
```
132+
133+
Prerequisite: `aigitcommit` is installed and available in your `PATH`.
118134

119135
**Prerequisites**
120136

121137
- `aigitcommit` must be installed and available in your `PATH`
122138
- Configure required environment variables before committing (see [Configuration](#configuration))
123139

124-
**Per-Repository Installation**
125-
126-
Install the hook for a single repository:
140+
**Manual install (alternative)**
127141

128142
```bash
129143
cp hooks/prepare-commit-msg .git/hooks/prepare-commit-msg
130144
chmod +x .git/hooks/prepare-commit-msg
131145
```
132146

133-
After installation, the hook runs automatically when you execute `git commit`. You can review and edit the generated message before finalizing the commit.
134-
135147
**Disable for a single commit**: Use `git commit --no-verify` to bypass the hook.
136148

137-
**Global Installation**
149+
**Global installation (optional)**
138150

139-
Set up the hook for all new and existing repositories using Git templates:
151+
Use Git templates so new repos have the hook:
140152

141153
```bash
142-
# Create template directory structure
143154
mkdir -p ~/.git-template/hooks
144155
cp hooks/prepare-commit-msg ~/.git-template/hooks/prepare-commit-msg
145156
chmod +x ~/.git-template/hooks/prepare-commit-msg
146-
147-
# Configure Git to use this template for new repositories
148157
git config --global init.templateDir ~/.git-template
158+
```
149159

150-
# Apply to existing repositories
151-
# Option 1: Copy manually
152-
cp ~/.git-template/hooks/prepare-commit-msg <repo>/.git/hooks/
160+
Apply to an existing repo (either copy the file or re-init):
153161

154-
# Option 2: Re-initialize (safe, preserves existing data)
162+
```bash
163+
cp ~/.git-template/hooks/prepare-commit-msg <repo>/.git/hooks/
164+
# or
155165
cd <repo> && git init
156166
```
157167

158-
**Important**: Setting `core.hooksPath` globally overrides all repository hooks. The template approach is more flexible and recommended.
159-
160-
**Hook Behavior**
161-
162-
The hook only runs when:
163-
- You execute `git commit` (interactive mode) with no pre-written message
164-
- You execute `git commit -m ""` (explicit empty message)
168+
**Hook behavior (summary)**
165169

166-
The hook skips execution for:
167-
- Commits with pre-written messages (`git commit -m "message"`)
168-
- Merge commits, rebase, cherry-pick, or other automated commits
169-
- When the commit message file already contains non-comment content
170+
- Triggers on `git commit` with no message or with `-m ""`.
171+
- Skips merge/rebase/cherry-pick and commits with an existing message.
170172

171173
**Troubleshooting**
172174

0 commit comments

Comments
 (0)