gdiff-cli 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gdiff_cli-2.0.0/LICENSE +21 -0
- gdiff_cli-2.0.0/PKG-INFO +316 -0
- gdiff_cli-2.0.0/README.md +290 -0
- gdiff_cli-2.0.0/pyproject.toml +78 -0
- gdiff_cli-2.0.0/setup.cfg +4 -0
- gdiff_cli-2.0.0/src/gdiff/__init__.py +1 -0
- gdiff_cli-2.0.0/src/gdiff/__main__.py +5 -0
- gdiff_cli-2.0.0/src/gdiff/cli.py +123 -0
- gdiff_cli-2.0.0/src/gdiff/clipboard.py +44 -0
- gdiff_cli-2.0.0/src/gdiff/commands/__init__.py +0 -0
- gdiff_cli-2.0.0/src/gdiff/commands/generate.py +94 -0
- gdiff_cli-2.0.0/src/gdiff/commands/message.py +45 -0
- gdiff_cli-2.0.0/src/gdiff/commands/rule.py +91 -0
- gdiff_cli-2.0.0/src/gdiff/data/rule.txt +35 -0
- gdiff_cli-2.0.0/src/gdiff/errors.py +15 -0
- gdiff_cli-2.0.0/src/gdiff/git.py +124 -0
- gdiff_cli-2.0.0/src/gdiff/rules.py +129 -0
- gdiff_cli-2.0.0/src/gdiff/ui.py +47 -0
- gdiff_cli-2.0.0/src/gdiff_cli.egg-info/PKG-INFO +316 -0
- gdiff_cli-2.0.0/src/gdiff_cli.egg-info/SOURCES.txt +28 -0
- gdiff_cli-2.0.0/src/gdiff_cli.egg-info/dependency_links.txt +1 -0
- gdiff_cli-2.0.0/src/gdiff_cli.egg-info/entry_points.txt +2 -0
- gdiff_cli-2.0.0/src/gdiff_cli.egg-info/top_level.txt +1 -0
- gdiff_cli-2.0.0/tests/test_cli.py +520 -0
- gdiff_cli-2.0.0/tests/test_clipboard.py +226 -0
- gdiff_cli-2.0.0/tests/test_errors.py +19 -0
- gdiff_cli-2.0.0/tests/test_generate.py +313 -0
- gdiff_cli-2.0.0/tests/test_git.py +474 -0
- gdiff_cli-2.0.0/tests/test_rules.py +419 -0
- gdiff_cli-2.0.0/tests/test_ui.py +338 -0
gdiff_cli-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crazy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
gdiff_cli-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gdiff-cli
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Copy your git diff plus a commit-message rule to the clipboard
|
|
5
|
+
Author-email: crazy <0crazy.dev@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/0Crazy-0/gdiff
|
|
8
|
+
Project-URL: Issues, https://github.com/0Crazy-0/gdiff/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/0Crazy-0/gdiff/releases
|
|
10
|
+
Keywords: git,diff,commit,conventional-commits,clipboard,llm,cli
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
21
|
+
Classifier: Topic :: Utilities
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# gdiff
|
|
28
|
+
|
|
29
|
+
> **A tiny, 100% local, and free CLI that bridges your git history and any LLM: generate conventional commit messages from your staged changes, or revisit past commits to review or rewrite them.**
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
[](#windows-installation)
|
|
34
|
+
[](#debian)
|
|
35
|
+
[](#fedora)
|
|
36
|
+
[](#arch)
|
|
37
|
+
[](#linux--macos)
|
|
38
|
+
[](https://opensource.org/licenses/MIT)
|
|
39
|
+
[](https://www.python.org/)
|
|
40
|
+
[](#)
|
|
41
|
+
|
|
42
|
+
Have you ever spent 10 minutes staring at a terminal, trying to figure out what to write in your commit message? Or needed to quickly re-read an old commit, or hand it to an LLM? `gdiff` is built to solve exactly that, without the bloated dependencies, paid API keys, or heavy local setups that other commit-helpers force upon you.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## What Can It Do?
|
|
47
|
+
|
|
48
|
+
`gdiff` has three modes. Pick the one that matches what you are looking at:
|
|
49
|
+
|
|
50
|
+
| Command | Reads | Output | Rule appended |
|
|
51
|
+
| :--- | :--- | :--- | :---: |
|
|
52
|
+
| `gdiff` | your staged changes | clipboard | yes |
|
|
53
|
+
| `gdiff -c [REF]` | the diff of a past commit | clipboard | yes |
|
|
54
|
+
| `gdiff message [REF]` | the message of a past commit | terminal | no |
|
|
55
|
+
|
|
56
|
+
Two modifiers tweak the diff output: `-p` prints instead of copying, and `-d` copies only the diff, without the rule. You can also manage your prompt rule with `gdiff rule <path|init|reset>`.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## The Philosophy Behind gdiff
|
|
61
|
+
|
|
62
|
+
Most AI commit assistants are overly complicated. They demand:
|
|
63
|
+
* **Heavy environments**: Large `npm` installations, heavy dependency trees, and background runtime processes.
|
|
64
|
+
* **Paid API Keys**: Subscriptions to proprietary models (which can get expensive).
|
|
65
|
+
* **Opaque and Static Prompts**: Prompts hardcoded behind the scenes that output generic, dry commit descriptions that do not truly capture the essence or tone of your work.
|
|
66
|
+
|
|
67
|
+
`gdiff` takes a completely different, **human-centric, ultra-lightweight approach**:
|
|
68
|
+
|
|
69
|
+
1. **No API Keys & Completely Free**: It doesn't connect directly to any API. It sends your diffs + prompt guidelines to your system clipboard, so you can paste them anywhere: **any web LLM interface** (Gemini, ChatGPT, Claude), your **IDE-integrated AI chat**, or **any agent CLI** (opencode, Claude Code, Codex, agy). You can also teach your agent to run `gdiff --print` on its own, so it reads your rule and writes the commit for you, for example right after finishing a feature or a refactor.
|
|
70
|
+
2. **100% Customizable Prompts**: Your rules live in a plain text file (`rule.txt`). You can easily tweak the guidelines to fit the way you work: your team's conventions, your project, or your personal style.
|
|
71
|
+
3. **Your Whole History, Not Just What Is Staged**: Write a message for new changes, or grab the diff and message of any past commit to read it, review it, or hand it to an LLM.
|
|
72
|
+
4. **Zero-Dependency & Cross-Platform**: Written in pure Python (3.10+) using only the standard library—no third-party packages required. Runs natively on **Linux**, **macOS**, and **Windows** with only `git` and a system clipboard tool.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
### 1. Installation
|
|
79
|
+
|
|
80
|
+
**Requirements:**
|
|
81
|
+
* **Python 3.10+**
|
|
82
|
+
* **Git**
|
|
83
|
+
* On Linux: a clipboard utility (`wl-clipboard` for Wayland, or `xclip` / `xsel` for X11). macOS (`pbcopy`) and Windows (`clip.exe`) have built-in clipboard tools.
|
|
84
|
+
|
|
85
|
+
#### System Package Managers & Universal Installers
|
|
86
|
+
|
|
87
|
+
| OS / Distro | Package Manager | Install Command | Update Command |
|
|
88
|
+
| :--- | :--- | :--- | :--- |
|
|
89
|
+
| <a id="windows-installation"></a>**Windows** (PowerShell / Git Bash / MSYS2) | Universal script | Run in **PowerShell** (also for **Git Bash / MSYS2** users): `irm https://raw.githubusercontent.com/0Crazy-0/gdiff/main/windows-setup.ps1 \| iex` <br> or from **WSL**: `curl -fsSL https://raw.githubusercontent.com/0Crazy-0/gdiff/main/install.sh \| sh` | re-run the same command |
|
|
90
|
+
| <a id="debian"></a>**Debian / Ubuntu** | APT | `curl -fsSL https://raw.githubusercontent.com/0Crazy-0/gdiff/main/debian-setup.sh \| sudo bash` | `sudo apt update && sudo apt install gdiff` |
|
|
91
|
+
| <a id="fedora"></a>**Fedora** | COPR (DNF) | `sudo dnf copr enable crazy/gdiff && sudo dnf install gdiff` | `sudo dnf upgrade gdiff` |
|
|
92
|
+
| <a id="arch"></a>**Arch Linux** | AUR | `yay -S gdiff` <br> `paru -S gdiff` | `yay -S gdiff` <br> `paru -S gdiff` <br> (or simply `yay` / `paru`) |
|
|
93
|
+
| <a id="linux--macos"></a>**Linux / macOS** (any distro) | Universal script | `curl -fsSL https://raw.githubusercontent.com/0Crazy-0/gdiff/main/install.sh \| sh` <br> (**Windows** users: use the PowerShell command in the [Windows Installation](#windows-installation) row instead) | re-run the same command |
|
|
94
|
+
|
|
95
|
+
#### Python Package Managers
|
|
96
|
+
|
|
97
|
+
Install `gdiff` globally using your preferred Python tool manager:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Using uv
|
|
101
|
+
uv tool install gdiff-cli
|
|
102
|
+
|
|
103
|
+
# Using pipx
|
|
104
|
+
pipx install gdiff-cli
|
|
105
|
+
|
|
106
|
+
# Using pip
|
|
107
|
+
pip install gdiff-cli
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Or install directly from GitHub:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
uv tool install git+https://github.com/0Crazy-0/gdiff.git
|
|
114
|
+
# or
|
|
115
|
+
pip install git+https://github.com/0Crazy-0/gdiff.git
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
<details>
|
|
119
|
+
<summary>Installing from a local clone (development)</summary>
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
git clone https://github.com/0Crazy-0/gdiff.git
|
|
123
|
+
cd gdiff
|
|
124
|
+
|
|
125
|
+
# Using uv (uv does not activate .venv, so prefix commands with "uv run")
|
|
126
|
+
uv sync
|
|
127
|
+
uv run gdiff --version
|
|
128
|
+
|
|
129
|
+
# Using pip
|
|
130
|
+
pip install -e .
|
|
131
|
+
gdiff --version
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
</details>
|
|
135
|
+
|
|
136
|
+
### 2. Prepare Your Changes
|
|
137
|
+
Stage the code changes you want to commit:
|
|
138
|
+
```bash
|
|
139
|
+
git add src/my-feature.js
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 3. Run gdiff
|
|
143
|
+
Execute the CLI tool in the root of your Git repository:
|
|
144
|
+
```bash
|
|
145
|
+
gdiff
|
|
146
|
+
```
|
|
147
|
+
*Output:*
|
|
148
|
+
```text
|
|
149
|
+
✓ Diff with default rule copied to clipboard
|
|
150
|
+
```
|
|
151
|
+
*(If you have initialized a custom user rule or passed `-r`, it prints `✓ Diff with rule copied to clipboard`.)*
|
|
152
|
+
|
|
153
|
+
### 4. Ask the AI and Commit!
|
|
154
|
+
Paste the clipboard contents into any AI chat, copy the suggested message, and commit:
|
|
155
|
+
```bash
|
|
156
|
+
git commit -m "feat(core): add authentication gateway"
|
|
157
|
+
```
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## How-To Guides (Recipes)
|
|
161
|
+
|
|
162
|
+
### How to Customize the Default Prompt Rule
|
|
163
|
+
Out of the box, `gdiff` uses its built-in conventional commits rule. To create your own editable copy in `~/.config/gdiff/rule.txt` (on Windows: `%APPDATA%\gdiff\rule.txt`):
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
gdiff rule init
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Then open and edit the generated file:
|
|
170
|
+
```bash
|
|
171
|
+
nano ~/.config/gdiff/rule.txt
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The next time you run `gdiff`, your customized prompt will automatically be appended.
|
|
175
|
+
|
|
176
|
+
* Check which rule file is currently active: `gdiff rule path`
|
|
177
|
+
* Reset your rule back to the built-in default: `gdiff rule reset`
|
|
178
|
+
|
|
179
|
+
### How to Use a One-off Rule
|
|
180
|
+
To use a custom `.txt` prompt file for a single execution:
|
|
181
|
+
```bash
|
|
182
|
+
gdiff --rule ./custom-rules.txt
|
|
183
|
+
# or
|
|
184
|
+
gdiff -r ./custom-rules.txt
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### How to Print Output Without Copying
|
|
188
|
+
If you want to view the exact prompt content that would be copied to the clipboard, or if you want to pipe the prompt output directly to a local terminal command, use the `--print` flag:
|
|
189
|
+
```bash
|
|
190
|
+
gdiff --print
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### How to Copy the Diff of an Existing Commit
|
|
194
|
+
If you want to copy or review the diff of a commit that has already been made instead of staged changes, use the `-c` or `--commit` flag with an optional position, commit hash, or ref:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Copy the diff of the latest commit (HEAD)
|
|
198
|
+
gdiff -c
|
|
199
|
+
|
|
200
|
+
# Copy the diff of the second most recent commit (next in git log)
|
|
201
|
+
gdiff -c 2
|
|
202
|
+
|
|
203
|
+
# Copy the diff of a specific commit by hash
|
|
204
|
+
gdiff -c a1b2c3d
|
|
205
|
+
|
|
206
|
+
# Copy the diff of a specific ref or tag
|
|
207
|
+
gdiff -c v2.0.0
|
|
208
|
+
|
|
209
|
+
# Print the diff of a commit to stdout without the rule
|
|
210
|
+
gdiff -c 2 -d -p
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
> **Note on merge commits:** Numeric positions count in `git log` order, so every reachable commit counts, including merge commits and the commits of merged branches. Regardless of position, for merge commits `gdiff` generates the diff against the first parent (the target branch that received the merge), so the diff shows all the changes introduced by the merge as a whole. The same position semantics apply to `gdiff message`.
|
|
214
|
+
|
|
215
|
+
### How to View an Existing Commit Message
|
|
216
|
+
If you only need to recall the exact message of a past commit (to reuse it, review it, or fix a typo) instead of its diff, use the `message` subcommand. It accepts the same kind of reference as `--commit` (a position, commit hash, or ref) and prints the message to the terminal exactly as it was written:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Print the message of the latest commit (HEAD)
|
|
220
|
+
gdiff message
|
|
221
|
+
|
|
222
|
+
# Print the message of the second most recent commit
|
|
223
|
+
gdiff message 2
|
|
224
|
+
|
|
225
|
+
# Print the message of a specific commit by hash or ref
|
|
226
|
+
gdiff message a1b2c3d
|
|
227
|
+
gdiff message v2.0.0
|
|
228
|
+
|
|
229
|
+
# Add a header with hash, author and date above the message
|
|
230
|
+
gdiff message 2 -i
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
*Output of `gdiff message -i`:*
|
|
234
|
+
```text
|
|
235
|
+
Commit: a1b2c3d4e5f6...
|
|
236
|
+
Short: a1b2c3d
|
|
237
|
+
Author: Your Name <you@example.com>
|
|
238
|
+
Date: Sat Nov 7 20:35:55 2026 -0500
|
|
239
|
+
|
|
240
|
+
feat(core): add authentication gateway
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
> **Note:** `gdiff message` prints to the terminal and never touches the clipboard or your rule file, so it skips rule resolution entirely. It cannot be combined with `-c`, `-r`, `-p`, or `-d`.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Reference
|
|
248
|
+
|
|
249
|
+
### Usage
|
|
250
|
+
```text
|
|
251
|
+
gdiff [flags]
|
|
252
|
+
gdiff <command> [args]
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Default Flags (`gdiff [flags]`)
|
|
256
|
+
|
|
257
|
+
| Flag | Long Option | Description |
|
|
258
|
+
| :--- | :--- | :--- |
|
|
259
|
+
| `-c [REF]` | `--commit [REF]` | Diff of a commit: position, hash or ref (default: `1` = latest commit `HEAD`). Positions count from the latest commit in `git log` order, including merge commits and the commits of merged branches. |
|
|
260
|
+
| `-r <file>` | `--rule <file>` | Path to a custom rule file (`.txt`) to append instead of the default. Cannot be combined with `-d`. |
|
|
261
|
+
| `-p` | `--print` | Print the output directly to `stdout` instead of copying to the clipboard. |
|
|
262
|
+
| `-d` | `--diff-only` | Copy only the diff, without appending the rule. Cannot be combined with `-r`. |
|
|
263
|
+
| `-v` | `--version` | Display the installed version. |
|
|
264
|
+
| `-h` | `--help` | Show help information. |
|
|
265
|
+
|
|
266
|
+
### Commands
|
|
267
|
+
|
|
268
|
+
#### `gdiff message [REF] [-i]`
|
|
269
|
+
Print a commit message to the terminal, exactly as written.
|
|
270
|
+
|
|
271
|
+
| Argument / Flag | Description |
|
|
272
|
+
| :--- | :--- |
|
|
273
|
+
| `REF` | Commit position, hash or ref (default: `1` = latest commit `HEAD`). |
|
|
274
|
+
| `-i`, `--info` | Prepend a header with the commit hash, short hash, author and date. |
|
|
275
|
+
| `-h`, `--help` | Show help information for `message`. |
|
|
276
|
+
|
|
277
|
+
#### `gdiff rule <path|init|reset>`
|
|
278
|
+
Show which rule file is used and manage your personal rule file.
|
|
279
|
+
|
|
280
|
+
| Action | Description |
|
|
281
|
+
| :--- | :--- |
|
|
282
|
+
| `path` | Show which rule file is currently being used. |
|
|
283
|
+
| `init` | Create an editable copy of the built-in default rule in your config directory (does not overwrite an existing file). |
|
|
284
|
+
| `reset` | Overwrite your user rule file with the built-in default rule (prompts for confirmation if one exists). |
|
|
285
|
+
|
|
286
|
+
### Rule Precedence Order
|
|
287
|
+
`gdiff` evaluates which rule file to use in the following strict hierarchy (from highest priority to lowest):
|
|
288
|
+
|
|
289
|
+
1. **Command-Line Override**: `--rule <file>` / `-r <file>` (must have a `.txt` extension).
|
|
290
|
+
2. **User Config**: `~/.config/gdiff/rule.txt` on Linux/macOS (respects `$XDG_CONFIG_HOME`), or `%APPDATA%\gdiff\rule.txt` on Windows. You can override the config directory on any OS with `$GDIFF_CONFIG_HOME`.
|
|
291
|
+
3. **Built-in Default Rule**: The default rule packaged inside `gdiff`.
|
|
292
|
+
|
|
293
|
+
### Supported Clipboard Managers
|
|
294
|
+
`gdiff` automatically detects your environment and picks the right clipboard tool:
|
|
295
|
+
* **Wayland**: `wl-copy` (from `wl-clipboard`, when `WAYLAND_DISPLAY` is set)
|
|
296
|
+
* **X11 (Xorg)**: `xclip` or `xsel` (when `DISPLAY` is set)
|
|
297
|
+
* **macOS**: `pbcopy` (built-in)
|
|
298
|
+
* **Windows / WSL / Git Bash**: `clip.exe` (built-in)
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Explanation
|
|
303
|
+
|
|
304
|
+
### Why Separating Prompt Logic from API Orchestration is Better
|
|
305
|
+
Many tools in the modern ecosystem execute API requests directly. While convenient, this introduces several flaws:
|
|
306
|
+
* **Privacy & API Keys**: It forces the user to buy API credits, expose sensitive credentials in configuration environments, or trust the CLI tool not to leak keys.
|
|
307
|
+
* **Obsolescence**: As models are deprecated, the client must be continuously updated.
|
|
308
|
+
* **Ineffective Prompts**: Hardcoded prompts cannot easily adapt to diverse workspaces.
|
|
309
|
+
|
|
310
|
+
By decoupling context gathering (`git diff`, `git show`, `git log`) and instruction formatting (`rule.txt`) from AI querying, `gdiff` remains resilient. The clipboard acts as a universal bridge, allowing you to use cutting-edge web models, local desktop clients, agent CLIs, or your workplace's AI endpoints seamlessly and at zero cost.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## License
|
|
315
|
+
|
|
316
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# gdiff
|
|
2
|
+
|
|
3
|
+
> **A tiny, 100% local, and free CLI that bridges your git history and any LLM: generate conventional commit messages from your staged changes, or revisit past commits to review or rewrite them.**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
[](#windows-installation)
|
|
8
|
+
[](#debian)
|
|
9
|
+
[](#fedora)
|
|
10
|
+
[](#arch)
|
|
11
|
+
[](#linux--macos)
|
|
12
|
+
[](https://opensource.org/licenses/MIT)
|
|
13
|
+
[](https://www.python.org/)
|
|
14
|
+
[](#)
|
|
15
|
+
|
|
16
|
+
Have you ever spent 10 minutes staring at a terminal, trying to figure out what to write in your commit message? Or needed to quickly re-read an old commit, or hand it to an LLM? `gdiff` is built to solve exactly that, without the bloated dependencies, paid API keys, or heavy local setups that other commit-helpers force upon you.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## What Can It Do?
|
|
21
|
+
|
|
22
|
+
`gdiff` has three modes. Pick the one that matches what you are looking at:
|
|
23
|
+
|
|
24
|
+
| Command | Reads | Output | Rule appended |
|
|
25
|
+
| :--- | :--- | :--- | :---: |
|
|
26
|
+
| `gdiff` | your staged changes | clipboard | yes |
|
|
27
|
+
| `gdiff -c [REF]` | the diff of a past commit | clipboard | yes |
|
|
28
|
+
| `gdiff message [REF]` | the message of a past commit | terminal | no |
|
|
29
|
+
|
|
30
|
+
Two modifiers tweak the diff output: `-p` prints instead of copying, and `-d` copies only the diff, without the rule. You can also manage your prompt rule with `gdiff rule <path|init|reset>`.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## The Philosophy Behind gdiff
|
|
35
|
+
|
|
36
|
+
Most AI commit assistants are overly complicated. They demand:
|
|
37
|
+
* **Heavy environments**: Large `npm` installations, heavy dependency trees, and background runtime processes.
|
|
38
|
+
* **Paid API Keys**: Subscriptions to proprietary models (which can get expensive).
|
|
39
|
+
* **Opaque and Static Prompts**: Prompts hardcoded behind the scenes that output generic, dry commit descriptions that do not truly capture the essence or tone of your work.
|
|
40
|
+
|
|
41
|
+
`gdiff` takes a completely different, **human-centric, ultra-lightweight approach**:
|
|
42
|
+
|
|
43
|
+
1. **No API Keys & Completely Free**: It doesn't connect directly to any API. It sends your diffs + prompt guidelines to your system clipboard, so you can paste them anywhere: **any web LLM interface** (Gemini, ChatGPT, Claude), your **IDE-integrated AI chat**, or **any agent CLI** (opencode, Claude Code, Codex, agy). You can also teach your agent to run `gdiff --print` on its own, so it reads your rule and writes the commit for you, for example right after finishing a feature or a refactor.
|
|
44
|
+
2. **100% Customizable Prompts**: Your rules live in a plain text file (`rule.txt`). You can easily tweak the guidelines to fit the way you work: your team's conventions, your project, or your personal style.
|
|
45
|
+
3. **Your Whole History, Not Just What Is Staged**: Write a message for new changes, or grab the diff and message of any past commit to read it, review it, or hand it to an LLM.
|
|
46
|
+
4. **Zero-Dependency & Cross-Platform**: Written in pure Python (3.10+) using only the standard library—no third-party packages required. Runs natively on **Linux**, **macOS**, and **Windows** with only `git` and a system clipboard tool.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
### 1. Installation
|
|
53
|
+
|
|
54
|
+
**Requirements:**
|
|
55
|
+
* **Python 3.10+**
|
|
56
|
+
* **Git**
|
|
57
|
+
* On Linux: a clipboard utility (`wl-clipboard` for Wayland, or `xclip` / `xsel` for X11). macOS (`pbcopy`) and Windows (`clip.exe`) have built-in clipboard tools.
|
|
58
|
+
|
|
59
|
+
#### System Package Managers & Universal Installers
|
|
60
|
+
|
|
61
|
+
| OS / Distro | Package Manager | Install Command | Update Command |
|
|
62
|
+
| :--- | :--- | :--- | :--- |
|
|
63
|
+
| <a id="windows-installation"></a>**Windows** (PowerShell / Git Bash / MSYS2) | Universal script | Run in **PowerShell** (also for **Git Bash / MSYS2** users): `irm https://raw.githubusercontent.com/0Crazy-0/gdiff/main/windows-setup.ps1 \| iex` <br> or from **WSL**: `curl -fsSL https://raw.githubusercontent.com/0Crazy-0/gdiff/main/install.sh \| sh` | re-run the same command |
|
|
64
|
+
| <a id="debian"></a>**Debian / Ubuntu** | APT | `curl -fsSL https://raw.githubusercontent.com/0Crazy-0/gdiff/main/debian-setup.sh \| sudo bash` | `sudo apt update && sudo apt install gdiff` |
|
|
65
|
+
| <a id="fedora"></a>**Fedora** | COPR (DNF) | `sudo dnf copr enable crazy/gdiff && sudo dnf install gdiff` | `sudo dnf upgrade gdiff` |
|
|
66
|
+
| <a id="arch"></a>**Arch Linux** | AUR | `yay -S gdiff` <br> `paru -S gdiff` | `yay -S gdiff` <br> `paru -S gdiff` <br> (or simply `yay` / `paru`) |
|
|
67
|
+
| <a id="linux--macos"></a>**Linux / macOS** (any distro) | Universal script | `curl -fsSL https://raw.githubusercontent.com/0Crazy-0/gdiff/main/install.sh \| sh` <br> (**Windows** users: use the PowerShell command in the [Windows Installation](#windows-installation) row instead) | re-run the same command |
|
|
68
|
+
|
|
69
|
+
#### Python Package Managers
|
|
70
|
+
|
|
71
|
+
Install `gdiff` globally using your preferred Python tool manager:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Using uv
|
|
75
|
+
uv tool install gdiff-cli
|
|
76
|
+
|
|
77
|
+
# Using pipx
|
|
78
|
+
pipx install gdiff-cli
|
|
79
|
+
|
|
80
|
+
# Using pip
|
|
81
|
+
pip install gdiff-cli
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Or install directly from GitHub:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
uv tool install git+https://github.com/0Crazy-0/gdiff.git
|
|
88
|
+
# or
|
|
89
|
+
pip install git+https://github.com/0Crazy-0/gdiff.git
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
<details>
|
|
93
|
+
<summary>Installing from a local clone (development)</summary>
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
git clone https://github.com/0Crazy-0/gdiff.git
|
|
97
|
+
cd gdiff
|
|
98
|
+
|
|
99
|
+
# Using uv (uv does not activate .venv, so prefix commands with "uv run")
|
|
100
|
+
uv sync
|
|
101
|
+
uv run gdiff --version
|
|
102
|
+
|
|
103
|
+
# Using pip
|
|
104
|
+
pip install -e .
|
|
105
|
+
gdiff --version
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
</details>
|
|
109
|
+
|
|
110
|
+
### 2. Prepare Your Changes
|
|
111
|
+
Stage the code changes you want to commit:
|
|
112
|
+
```bash
|
|
113
|
+
git add src/my-feature.js
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 3. Run gdiff
|
|
117
|
+
Execute the CLI tool in the root of your Git repository:
|
|
118
|
+
```bash
|
|
119
|
+
gdiff
|
|
120
|
+
```
|
|
121
|
+
*Output:*
|
|
122
|
+
```text
|
|
123
|
+
✓ Diff with default rule copied to clipboard
|
|
124
|
+
```
|
|
125
|
+
*(If you have initialized a custom user rule or passed `-r`, it prints `✓ Diff with rule copied to clipboard`.)*
|
|
126
|
+
|
|
127
|
+
### 4. Ask the AI and Commit!
|
|
128
|
+
Paste the clipboard contents into any AI chat, copy the suggested message, and commit:
|
|
129
|
+
```bash
|
|
130
|
+
git commit -m "feat(core): add authentication gateway"
|
|
131
|
+
```
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## How-To Guides (Recipes)
|
|
135
|
+
|
|
136
|
+
### How to Customize the Default Prompt Rule
|
|
137
|
+
Out of the box, `gdiff` uses its built-in conventional commits rule. To create your own editable copy in `~/.config/gdiff/rule.txt` (on Windows: `%APPDATA%\gdiff\rule.txt`):
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
gdiff rule init
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Then open and edit the generated file:
|
|
144
|
+
```bash
|
|
145
|
+
nano ~/.config/gdiff/rule.txt
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The next time you run `gdiff`, your customized prompt will automatically be appended.
|
|
149
|
+
|
|
150
|
+
* Check which rule file is currently active: `gdiff rule path`
|
|
151
|
+
* Reset your rule back to the built-in default: `gdiff rule reset`
|
|
152
|
+
|
|
153
|
+
### How to Use a One-off Rule
|
|
154
|
+
To use a custom `.txt` prompt file for a single execution:
|
|
155
|
+
```bash
|
|
156
|
+
gdiff --rule ./custom-rules.txt
|
|
157
|
+
# or
|
|
158
|
+
gdiff -r ./custom-rules.txt
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### How to Print Output Without Copying
|
|
162
|
+
If you want to view the exact prompt content that would be copied to the clipboard, or if you want to pipe the prompt output directly to a local terminal command, use the `--print` flag:
|
|
163
|
+
```bash
|
|
164
|
+
gdiff --print
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### How to Copy the Diff of an Existing Commit
|
|
168
|
+
If you want to copy or review the diff of a commit that has already been made instead of staged changes, use the `-c` or `--commit` flag with an optional position, commit hash, or ref:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Copy the diff of the latest commit (HEAD)
|
|
172
|
+
gdiff -c
|
|
173
|
+
|
|
174
|
+
# Copy the diff of the second most recent commit (next in git log)
|
|
175
|
+
gdiff -c 2
|
|
176
|
+
|
|
177
|
+
# Copy the diff of a specific commit by hash
|
|
178
|
+
gdiff -c a1b2c3d
|
|
179
|
+
|
|
180
|
+
# Copy the diff of a specific ref or tag
|
|
181
|
+
gdiff -c v2.0.0
|
|
182
|
+
|
|
183
|
+
# Print the diff of a commit to stdout without the rule
|
|
184
|
+
gdiff -c 2 -d -p
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
> **Note on merge commits:** Numeric positions count in `git log` order, so every reachable commit counts, including merge commits and the commits of merged branches. Regardless of position, for merge commits `gdiff` generates the diff against the first parent (the target branch that received the merge), so the diff shows all the changes introduced by the merge as a whole. The same position semantics apply to `gdiff message`.
|
|
188
|
+
|
|
189
|
+
### How to View an Existing Commit Message
|
|
190
|
+
If you only need to recall the exact message of a past commit (to reuse it, review it, or fix a typo) instead of its diff, use the `message` subcommand. It accepts the same kind of reference as `--commit` (a position, commit hash, or ref) and prints the message to the terminal exactly as it was written:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# Print the message of the latest commit (HEAD)
|
|
194
|
+
gdiff message
|
|
195
|
+
|
|
196
|
+
# Print the message of the second most recent commit
|
|
197
|
+
gdiff message 2
|
|
198
|
+
|
|
199
|
+
# Print the message of a specific commit by hash or ref
|
|
200
|
+
gdiff message a1b2c3d
|
|
201
|
+
gdiff message v2.0.0
|
|
202
|
+
|
|
203
|
+
# Add a header with hash, author and date above the message
|
|
204
|
+
gdiff message 2 -i
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
*Output of `gdiff message -i`:*
|
|
208
|
+
```text
|
|
209
|
+
Commit: a1b2c3d4e5f6...
|
|
210
|
+
Short: a1b2c3d
|
|
211
|
+
Author: Your Name <you@example.com>
|
|
212
|
+
Date: Sat Nov 7 20:35:55 2026 -0500
|
|
213
|
+
|
|
214
|
+
feat(core): add authentication gateway
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
> **Note:** `gdiff message` prints to the terminal and never touches the clipboard or your rule file, so it skips rule resolution entirely. It cannot be combined with `-c`, `-r`, `-p`, or `-d`.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Reference
|
|
222
|
+
|
|
223
|
+
### Usage
|
|
224
|
+
```text
|
|
225
|
+
gdiff [flags]
|
|
226
|
+
gdiff <command> [args]
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Default Flags (`gdiff [flags]`)
|
|
230
|
+
|
|
231
|
+
| Flag | Long Option | Description |
|
|
232
|
+
| :--- | :--- | :--- |
|
|
233
|
+
| `-c [REF]` | `--commit [REF]` | Diff of a commit: position, hash or ref (default: `1` = latest commit `HEAD`). Positions count from the latest commit in `git log` order, including merge commits and the commits of merged branches. |
|
|
234
|
+
| `-r <file>` | `--rule <file>` | Path to a custom rule file (`.txt`) to append instead of the default. Cannot be combined with `-d`. |
|
|
235
|
+
| `-p` | `--print` | Print the output directly to `stdout` instead of copying to the clipboard. |
|
|
236
|
+
| `-d` | `--diff-only` | Copy only the diff, without appending the rule. Cannot be combined with `-r`. |
|
|
237
|
+
| `-v` | `--version` | Display the installed version. |
|
|
238
|
+
| `-h` | `--help` | Show help information. |
|
|
239
|
+
|
|
240
|
+
### Commands
|
|
241
|
+
|
|
242
|
+
#### `gdiff message [REF] [-i]`
|
|
243
|
+
Print a commit message to the terminal, exactly as written.
|
|
244
|
+
|
|
245
|
+
| Argument / Flag | Description |
|
|
246
|
+
| :--- | :--- |
|
|
247
|
+
| `REF` | Commit position, hash or ref (default: `1` = latest commit `HEAD`). |
|
|
248
|
+
| `-i`, `--info` | Prepend a header with the commit hash, short hash, author and date. |
|
|
249
|
+
| `-h`, `--help` | Show help information for `message`. |
|
|
250
|
+
|
|
251
|
+
#### `gdiff rule <path|init|reset>`
|
|
252
|
+
Show which rule file is used and manage your personal rule file.
|
|
253
|
+
|
|
254
|
+
| Action | Description |
|
|
255
|
+
| :--- | :--- |
|
|
256
|
+
| `path` | Show which rule file is currently being used. |
|
|
257
|
+
| `init` | Create an editable copy of the built-in default rule in your config directory (does not overwrite an existing file). |
|
|
258
|
+
| `reset` | Overwrite your user rule file with the built-in default rule (prompts for confirmation if one exists). |
|
|
259
|
+
|
|
260
|
+
### Rule Precedence Order
|
|
261
|
+
`gdiff` evaluates which rule file to use in the following strict hierarchy (from highest priority to lowest):
|
|
262
|
+
|
|
263
|
+
1. **Command-Line Override**: `--rule <file>` / `-r <file>` (must have a `.txt` extension).
|
|
264
|
+
2. **User Config**: `~/.config/gdiff/rule.txt` on Linux/macOS (respects `$XDG_CONFIG_HOME`), or `%APPDATA%\gdiff\rule.txt` on Windows. You can override the config directory on any OS with `$GDIFF_CONFIG_HOME`.
|
|
265
|
+
3. **Built-in Default Rule**: The default rule packaged inside `gdiff`.
|
|
266
|
+
|
|
267
|
+
### Supported Clipboard Managers
|
|
268
|
+
`gdiff` automatically detects your environment and picks the right clipboard tool:
|
|
269
|
+
* **Wayland**: `wl-copy` (from `wl-clipboard`, when `WAYLAND_DISPLAY` is set)
|
|
270
|
+
* **X11 (Xorg)**: `xclip` or `xsel` (when `DISPLAY` is set)
|
|
271
|
+
* **macOS**: `pbcopy` (built-in)
|
|
272
|
+
* **Windows / WSL / Git Bash**: `clip.exe` (built-in)
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Explanation
|
|
277
|
+
|
|
278
|
+
### Why Separating Prompt Logic from API Orchestration is Better
|
|
279
|
+
Many tools in the modern ecosystem execute API requests directly. While convenient, this introduces several flaws:
|
|
280
|
+
* **Privacy & API Keys**: It forces the user to buy API credits, expose sensitive credentials in configuration environments, or trust the CLI tool not to leak keys.
|
|
281
|
+
* **Obsolescence**: As models are deprecated, the client must be continuously updated.
|
|
282
|
+
* **Ineffective Prompts**: Hardcoded prompts cannot easily adapt to diverse workspaces.
|
|
283
|
+
|
|
284
|
+
By decoupling context gathering (`git diff`, `git show`, `git log`) and instruction formatting (`rule.txt`) from AI querying, `gdiff` remains resilient. The clipboard acts as a universal bridge, allowing you to use cutting-edge web models, local desktop clients, agent CLIs, or your workplace's AI endpoints seamlessly and at zero cost.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
This project is licensed under the [MIT License](LICENSE).
|