Git Commit

Git Commit

Examines the diff, stages related files, writes a Conventional Commits message and runs git commit, splitting changes into several commits when needed.

Skill files1 file
SKILL.md164 lines
1
---
2
name: git-commit
3
description: 'Use this skill when the user wants to make a Git commit or split changes into more than one commit. Also use it when the user types "/commit" or asks for a conventional commit. The skill examines the diff, stages the related files, writes a Conventional Commits message, and runs git commit. Do not use it when the user wants only a commit message and no commit. Do not use it to push, open a pull request, rebase, or change the commit history.'
4
license: MIT
5
compatibility: 'Requires Git. The `--resolved` option of `git add` requires Git 2.56 or later. Older versions use the fallback in step 3.'
6
allowed-tools: shell(git:*)
7
---
8
9
# Git Commit with Conventional Commits
10
11
Make Git commits that follow the [Conventional Commits 1.0.0](https://www.conventionalcommits.org/en/v1.0.0/) specification. Get the type, the scope, and the summary from the diff.
12
13
## Message Format
14
15
```text
16
<type>(<scope>): <summary>
17
18
<body>
19
20
<footer>
21
```
22
23
- The scope, the body, and the footer are optional. Without a scope, write `<type>: <summary>`.
24
- Write the summary in the imperative mood: "add", not "added" or "adds".
25
- Keep the first line at 72 characters or less. Do not put a period at the end.
26
- In the body, tell what changed and why.
27
- Write each footer as `Token: value` or `Token #value`, for example `Refs: #456` or `Closes #123`. Conventional Commits accepts the two forms, but Git reads only `Token: value` as a trailer. In a token, use `-` in place of a space.
28
29
## Types
30
31
Conventional Commits defines only `feat` and `fix`. The other types come from the Angular convention ([`@commitlint/config-conventional`](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional)). If the repository has its own list, use that list.
32
33
| Type | Use it for |
34
| ---------- | ---------------------------------------------- |
35
| `feat` | A new feature |
36
| `fix` | A bug fix |
37
| `docs` | Documentation only |
38
| `style` | Formatting only, with no change to the logic |
39
| `refactor` | A code change that is not a feature or a fix |
40
| `perf` | A performance improvement |
41
| `test` | New or changed tests |
42
| `build` | The build system or the dependencies |
43
| `ci` | The CI configuration |
44
| `chore` | Other maintenance |
45
| `revert` | A revert of an earlier commit |
46
47
## Breaking Changes
48
49
Put `!` before the colon, or add a `BREAKING CHANGE:` footer. Write the token in uppercase. `BREAKING-CHANGE:` is also correct.
50
51
```text
52
feat(api)!: remove the v1 endpoints
53
54
BREAKING CHANGE: Clients must use the v2 endpoints.
55
```
56
57
## Workflow
58
59
### 1. Read the repository rules
60
61
Find the commit rules before you write a message:
62
63
- A commitlint configuration, for example `commitlint.config.js` or `.commitlintrc.json`.
64
- `CONTRIBUTING.md`.
65
- The recent messages: `git log --oneline -10`.
66
67
If a repository rule is different from this skill, use the repository rule.
68
69
### 2. Examine the changes
70
71
```bash
72
git status --porcelain
73
git diff --staged
74
git diff
75
```
76
77
If there are no changes, run the checks at the start of step 3. If they find `MERGE_HEAD`, continue. If not, tell the user what `git status --long` shows. Do not make an empty commit.
78
79
### 3. Stage the files
80
81
First, check for an operation in progress. Run each command alone. Do not chain them with `&&`. In a subdirectory, run every command in this step as `git -C <root> ...`. `git rev-parse --show-toplevel` prints the root.
82
83
```bash
84
git rev-parse -q --verify --symbolic-full-name MERGE_HEAD
85
git rev-parse -q --verify --symbolic-full-name CHERRY_PICK_HEAD
86
git rev-parse -q --verify --symbolic-full-name REVERT_HEAD
87
git diff --name-only --diff-filter=U --no-relative
88
git status --long
89
```
90
91
A `rev-parse` command prints a ref name if its operation is in progress. If not, the command prints nothing and exits with status 1. The `git diff` command lists unmerged files. It finds conflicts that have no ref, for example from `git stash pop`. `git status --long` shows the other cases.
92
93
**If an operation is in progress or there are unmerged files**, do not unstage files. Do not split the commit. The index holds the result of the operation. If you unstage a file, Git drops the changes of the other side or removes a conflict entry.
94
95
- Stop and tell the user if `git status --long` shows "rebase in progress", "You are in the middle of an am session", "Cherry-pick currently in progress", or "Revert currently in progress".
96
- Run `git status --porcelain=v2`. A line that starts with `u` shows an unmerged file. You can resolve the file only if all these conditions are true:
97
- The line starts with `u UU N...` or `u AA N...`.
98
- Each mode on the line is `100644`, `100755`, or `000000`.
99
- `git diff --no-relative` does not show `Binary files differ` for the file.
100
- Ask the user how to resolve all other unmerged files. Git cannot find conflict markers in these files. `git add --resolved` and the checks below stage these files without a warning. Stage each of these files only after the user resolves it: `git add -- <path>`.
101
- With Git 2.56 or later, stage the files that you can resolve with `git add --resolved -- <paths>`.
102
- With older Git, check those files and stage them:
103
104
```bash
105
git diff --check -- path/to/file1 path/to/file2
106
git add -- path/to/file1 path/to/file2
107
```
108
109
- Stage the files only if `git diff --check` finds no "leftover conflict marker" line. Ignore whitespace warnings from the other branch.
110
- Then, with any Git version, run `git diff --name-only --no-relative` and `git ls-files --others --exclude-standard`. They list edits in other files. Skip the files that are still unmerged.
111
- Show these paths to the user. Ask if they belong to the commit. Stage only the approved paths with `git add -- <paths>`.
112
- Git quotes some paths, for example paths with non-ASCII characters. `git add` fails for a quoted path. Ask the user about these files.
113
114
**If there is no operation and no unmerged file**, put one logical change in each commit. If the staged files contain more than one change, first unstage the files of the other changes. Then stage the files for this change:
115
116
```bash
117
git reset -q -- path/to/other-file1 path/to/other-file2
118
git add -- path/to/file1 path/to/file2
119
git add -- '*.test.*'
120
git add -- src/components/
121
```
122
123
- Put a glob in quotes. Without quotes, the shell expands the glob and does not find the files in subdirectories.
124
- Do not use `git add -p` or `git add -i`. These commands wait for input from a person.
125
- Examine the list of staged files with `git diff --staged --name-only`. Do not commit secrets, for example `.env` files, `credentials.json`, or private keys.
126
127
### 4. Write the message
128
129
Get each part from the diff:
130
131
- **Type**: The kind of change.
132
- **Scope**: The module or the area that the change affects.
133
- **Summary**: What changed, in one line.
134
135
### 5. Commit
136
137
When step 3 finds `MERGE_HEAD`, `CHERRY_PICK_HEAD`, or `REVERT_HEAD`, run `git commit --no-edit` with no paths and no `--cleanup` option. This keeps the message that Git prepared. Do not write a new `-m` message. The message can keep the `Conflicts:` comment lines from Git. Do not remove them.
138
139
In all other cases:
140
141
Give each paragraph with a different `-m` option. Git puts a blank line between the paragraphs. This command works in Bash, PowerShell, and other shells.
142
143
```bash
144
git commit -m "feat(auth): add token refresh"
145
git commit -m "fix(parser): accept empty input" -m "An empty file caused a crash." -m "Closes: #123"
146
```
147
148
For a long message, write the message to a temporary file. Then run `git commit -F <file>`.
149
150
### 6. Make sure that the commit is correct
151
152
```bash
153
git log -1 --stat --first-parent
154
git status --porcelain
155
```
156
157
## Safety Rules
158
159
- Do not change the Git configuration.
160
- Do not use `--no-verify` unless the user tells you to. Hooks can be in `.git/hooks` or in the Git configuration.
161
- If a hook fails, Git does not make the commit. Fix the problem, stage the files again, and run the same `git commit` command again. Do not use `--amend`, because it changes the previous commit.
162
- Do not change the commit history unless the user tells you to. Do not use `git reset --hard`, `git rebase`, or the experimental `git history` command.
163
- Do not push unless the user tells you to. Do not force push to the default branch.
164

© awesome-copilot contributors · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,689 prompts

More by @OpenSourceBuffGuy

See all
Quiet Kyoto autumn travel vlog, 30 seconds prompt image

Quiet Kyoto autumn travel vlog, 30 seconds

Generates a slow, natural 30-second autumn travel vlog in Kyoto of the woman from a reference image, with short casual dialogue, handheld camera and film grain, avoiding an ad look.

video-prompt, vlog, reference-image, character-consistency, handheld, film-grain, home-video, travel, japan, multi-shot, lip-sync, natural-light, guardrails, seedance, for-content-creators, timed-beats, long-form, casual, candid, autumn

Ice heroine fights hunters in Seoul parking garage prompt image

Ice heroine fights hunters in Seoul parking garage

Plans a 30-second supernatural action film where an ice-powered heroine defends a puppy from hunters in a Seoul parking garage, with identity locked to two reference images.

video-prompt, kling, timed-beats, multi-shot, action, martial-arts, visual-effects, character-consistency, reference-image, korea, cityscape, night-scene, slow-motion, tracking-shot, cinematic, creatures, film-score, negative-prompt, dramatic-lighting, neon, advanced, lip-sync, woman

Floating pan-fried gyoza with ponzu splash prompt image

Floating pan-fried gyoza with ponzu splash

Generates a macro food photograph of pan-fried gyoza floating in zero gravity with a ponzu splash, sesame droplets and green onion confetti under warm side light.

image-prompt, food-photography, photorealistic, cinematic, macro, nano-banana, dramatic-lighting, vertical-format, still-life, cooking, japan, golden-hour, for-photographers, restaurants, bokeh, advanced

Reviews

Loading reviews…

Discussion

Loading comments…