@nemo-cli/git 0.1.2 → 0.1.4
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.
- package/README.md +696 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1207 -74
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,44 +1,722 @@
|
|
|
1
1
|
# `@nemo-cli/git`
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Enhanced Git workflow CLI with interactive prompts, automatic stash handling, and conventional commits support.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Global installation (recommended)
|
|
9
|
+
npm install -g @nemo-cli/git
|
|
10
|
+
|
|
11
|
+
# Or using pnpm
|
|
12
|
+
pnpm add @nemo-cli/git --global
|
|
8
13
|
```
|
|
9
14
|
|
|
15
|
+
## Key Features
|
|
16
|
+
|
|
17
|
+
- **Interactive Prompts**: User-friendly interface for all git operations
|
|
18
|
+
- **Auto Stash/Pop**: Automatically stashes changes before checkout/merge/pull, then restores them
|
|
19
|
+
- **Conventional Commits**: Interactive commit wizard with type/scope selection from your commitlint config
|
|
20
|
+
- **Smart Branch Management**: Advanced branch operations with merge status and time filtering
|
|
21
|
+
- **Ticket Auto-Detection**: Automatically extracts ticket numbers from branch names for commit messages
|
|
22
|
+
- **Interactive Commit Navigator**: Enhanced `ng blame` for browsing file history with full diff support
|
|
23
|
+
- **Visual History Viewer**: Beautiful `ng hist` command with interactive graph display and keyboard navigation
|
|
24
|
+
|
|
10
25
|
## Usage
|
|
11
26
|
|
|
27
|
+
The CLI provides the `ng` command as an enhanced replacement for git operations.
|
|
28
|
+
|
|
29
|
+
### Getting Help
|
|
30
|
+
|
|
12
31
|
```bash
|
|
13
|
-
# help
|
|
32
|
+
# Show main help
|
|
14
33
|
ng -h
|
|
15
|
-
|
|
34
|
+
|
|
35
|
+
# Show help for specific command
|
|
16
36
|
ng <command> -h
|
|
37
|
+
# Example:
|
|
38
|
+
ng commit -h
|
|
39
|
+
ng branch -h
|
|
40
|
+
ng blame -h
|
|
41
|
+
ng hist -h
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Commands
|
|
17
47
|
|
|
18
|
-
|
|
48
|
+
### Commit (`ng commit`)
|
|
49
|
+
|
|
50
|
+
Interactive commit workflow with conventional commits support.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
19
53
|
ng commit
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Features:**
|
|
57
|
+
- ✅ Shows staged and unstaged files
|
|
58
|
+
- ✅ Interactive file selection for staging
|
|
59
|
+
- ✅ Runs `lint-staged` before committing (configurable)
|
|
60
|
+
- ✅ Reads commit type and scope from your `commitlint.config.*`
|
|
61
|
+
- ✅ Auto-detects ticket number from branch name
|
|
62
|
+
- Supports: `feature/PRIME-1500`, `JIRA-123`, `123`, etc.
|
|
63
|
+
- ✅ Validates commit message (max 80 chars for title)
|
|
64
|
+
- ✅ Optional body/description
|
|
65
|
+
- ✅ Commit preview with colored output
|
|
66
|
+
- ✅ Optional push after commit
|
|
67
|
+
|
|
68
|
+
**Supported ticket formats:**
|
|
69
|
+
- `PRIME-1500`, `JIRA-123` (slash format)
|
|
70
|
+
- `PRIME_1500`, `JIRA_123` (underscore format)
|
|
71
|
+
- `1500` (number only)
|
|
72
|
+
|
|
73
|
+
---
|
|
20
74
|
|
|
21
|
-
|
|
22
|
-
|
|
75
|
+
### Pull (`ng pull` / `ng pl`)
|
|
76
|
+
|
|
77
|
+
Pull changes with automatic stash handling.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Interactive mode (default)
|
|
23
81
|
ng pull
|
|
24
82
|
|
|
25
|
-
#
|
|
26
|
-
ng
|
|
83
|
+
# Rebase mode
|
|
84
|
+
ng pull -r
|
|
85
|
+
ng pull --rebase
|
|
86
|
+
|
|
87
|
+
# Merge mode (default)
|
|
88
|
+
ng pull -m
|
|
89
|
+
ng pull --merge
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Features:**
|
|
93
|
+
- ✅ Select any remote branch to pull
|
|
94
|
+
- ✅ Auto stash before pull, pop after
|
|
95
|
+
- ✅ Choose between merge or rebase mode
|
|
96
|
+
- ✅ Defaults to pulling current branch
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### Push (`ng push` / `ng ps`)
|
|
101
|
+
|
|
102
|
+
Push current branch to remote.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
27
105
|
ng push
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Features:**
|
|
109
|
+
- ✅ Pushes current branch to remote
|
|
110
|
+
- ✅ Interactive confirmation
|
|
111
|
+
|
|
112
|
+
---
|
|
28
113
|
|
|
29
|
-
|
|
30
|
-
|
|
114
|
+
### Checkout (`ng checkout` / `ng co`)
|
|
115
|
+
|
|
116
|
+
Switch branches with automatic stash handling.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Interactive branch selection (default: local)
|
|
31
120
|
ng checkout
|
|
32
121
|
|
|
33
|
-
#
|
|
34
|
-
|
|
122
|
+
# Local branches only
|
|
123
|
+
ng checkout -l
|
|
124
|
+
|
|
125
|
+
# Remote branches only
|
|
126
|
+
ng checkout -r
|
|
127
|
+
|
|
128
|
+
# Create and checkout new branch
|
|
129
|
+
ng checkout -b
|
|
130
|
+
ng checkout -b feature/my-branch
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Creating new branches:**
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# Interactive creation with branch type prefix
|
|
35
137
|
ng co -b
|
|
138
|
+
# Prompts you to select:
|
|
139
|
+
# 1. Branch type: feature/PRIME-, feature/, bugfix/
|
|
140
|
+
# 2. Branch name (max 15 chars)
|
|
141
|
+
|
|
142
|
+
# Direct creation
|
|
143
|
+
ng co -b feature/PRIME-1500
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Features:**
|
|
147
|
+
- ✅ Auto stash before checkout, pop after
|
|
148
|
+
- ✅ Interactive branch selection
|
|
149
|
+
- ✅ Separate lists for local and remote branches
|
|
150
|
+
- ✅ Create new branch with prefix templates
|
|
151
|
+
- ✅ Branch name validation
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### Branch Management (`ng branch`)
|
|
36
156
|
|
|
37
|
-
|
|
157
|
+
Advanced branch operations.
|
|
158
|
+
|
|
159
|
+
#### Delete Branches
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Delete local branches
|
|
38
163
|
ng branch delete
|
|
39
|
-
|
|
164
|
+
|
|
165
|
+
# Delete remote branches
|
|
40
166
|
ng branch delete -r
|
|
167
|
+
ng branch delete --remote
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Features:**
|
|
171
|
+
- ✅ Shows merge status: `(merged)` or `(not merged)`
|
|
172
|
+
- ✅ Displays last commit time
|
|
173
|
+
- ✅ Multi-select support
|
|
174
|
+
- ✅ Safety check for unmerged branches (requires confirmation)
|
|
175
|
+
- ✅ Excludes: `main`, `master`, `develop`
|
|
176
|
+
|
|
177
|
+
#### Clean Merged Branches
|
|
41
178
|
|
|
42
|
-
|
|
179
|
+
```bash
|
|
43
180
|
ng branch clean
|
|
44
181
|
```
|
|
182
|
+
|
|
183
|
+
**Features:**
|
|
184
|
+
- ✅ Only deletes branches merged to main/master/develop
|
|
185
|
+
- ✅ Time-based filtering:
|
|
186
|
+
- All merged branches
|
|
187
|
+
- Merged branches older than 1 month
|
|
188
|
+
- Merged branches older than 3 months
|
|
189
|
+
- Merged branches older than 1 year
|
|
190
|
+
- ✅ Shows list of branches before deletion
|
|
191
|
+
- ✅ Interactive confirmation
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### List Branches (`ng list` / `ng ls`)
|
|
196
|
+
|
|
197
|
+
List branches with current branch indicator.
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
# List all branches (default)
|
|
201
|
+
ng list
|
|
202
|
+
|
|
203
|
+
# Local branches only
|
|
204
|
+
ng list -l
|
|
205
|
+
ng list --local
|
|
206
|
+
|
|
207
|
+
# Remote branches only
|
|
208
|
+
ng list -r
|
|
209
|
+
ng list --remote
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Features:**
|
|
213
|
+
- ✅ Shows branch counts
|
|
214
|
+
- ✅ Highlights current branch
|
|
215
|
+
- ✅ Separate sections for local and remote branches
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### Merge Branches (`ng merge` / `ng mg`)
|
|
220
|
+
|
|
221
|
+
Merge branches with automatic stash handling.
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# Interactive branch selection
|
|
225
|
+
ng merge
|
|
226
|
+
|
|
227
|
+
# Direct merge
|
|
228
|
+
ng merge feature/my-branch
|
|
229
|
+
|
|
230
|
+
# Merge local branch
|
|
231
|
+
ng merge -l
|
|
232
|
+
|
|
233
|
+
# Merge remote branch
|
|
234
|
+
ng merge -r
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Features:**
|
|
238
|
+
- ✅ Auto stash before merge, pop after
|
|
239
|
+
- ✅ Interactive branch selection with search
|
|
240
|
+
- ✅ Supports both local and remote branches
|
|
241
|
+
- ✅ Interactive confirmation for remote branches
|
|
242
|
+
- ✅ Direct argument support for quick merges
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
### Interactive Commit Navigator (`ng blame`)
|
|
247
|
+
|
|
248
|
+
Browse file commit history with full diff support and interactive navigation.
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# View commit history for a file
|
|
252
|
+
ng blame <file-path>
|
|
253
|
+
|
|
254
|
+
# Example
|
|
255
|
+
ng blame src/commands/blame.ts
|
|
256
|
+
ng blame packages/git/src/commands/blame.ts
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Features:**
|
|
260
|
+
- ✅ **Full Diff Display**: Shows complete diff for each commit (not just commit messages)
|
|
261
|
+
- ✅ **Interactive Navigation**: Browse through commits with keyboard shortcuts
|
|
262
|
+
- ✅ **Smart Caching**: Fetches git history once, then navigates instantly
|
|
263
|
+
- ✅ **Binary File Support**: Detects and handles binary files gracefully
|
|
264
|
+
- ✅ **Large Diff Protection**: Limits display to 50 lines to prevent terminal overflow
|
|
265
|
+
- ✅ **Follow File Renames**: Uses `--follow` to track history across renames
|
|
266
|
+
|
|
267
|
+
**Interactive Controls:**
|
|
268
|
+
|
|
269
|
+
| Key | Action | Description |
|
|
270
|
+
|-----|--------|-------------|
|
|
271
|
+
| `n` | Next commit | Move forward in time (to newer commits) |
|
|
272
|
+
| `p` | Previous commit | Move backward in time (to older commits) |
|
|
273
|
+
| `j` | Jump | Jump to a specific commit by number |
|
|
274
|
+
| `q` | Quit | Exit the navigator |
|
|
275
|
+
|
|
276
|
+
**Display Information:**
|
|
277
|
+
|
|
278
|
+
Each commit shows:
|
|
279
|
+
- 📝 Commit number (e.g., `Commit 3/10`)
|
|
280
|
+
- 🔖 Short commit hash (8 characters, colored)
|
|
281
|
+
- 👤 Author name (colored)
|
|
282
|
+
- 📅 Commit date (dimmed)
|
|
283
|
+
- 💬 Commit message
|
|
284
|
+
- 📄 Full diff with git standard formatting (red for deletions, green for additions)
|
|
285
|
+
|
|
286
|
+
**Special Handling:**
|
|
287
|
+
|
|
288
|
+
- **Binary Files**: Shows "📄 Binary file - diff not available" instead of binary content
|
|
289
|
+
- **Large Diffs**: Displays first 50 lines with truncation notice
|
|
290
|
+
```
|
|
291
|
+
(Showing first 50 lines of 123)
|
|
292
|
+
... (truncated)
|
|
293
|
+
```
|
|
294
|
+
- **Empty History**: Warns if file has no git history
|
|
295
|
+
- **Missing Files**: Clear error if file doesn't exist
|
|
296
|
+
|
|
297
|
+
**Example Output:**
|
|
298
|
+
|
|
299
|
+
```
|
|
300
|
+
Found 10 commits for src/commands/blame.ts
|
|
301
|
+
Use [n/p] to navigate, [j] to jump, [q] to quit
|
|
302
|
+
|
|
303
|
+
📝 Commit 1/10
|
|
304
|
+
abc123de - John Doe - Mon Feb 2 12:00:00 2026
|
|
305
|
+
feat(git): add interactive commit navigator
|
|
306
|
+
|
|
307
|
+
--- Diff ---
|
|
308
|
+
diff --git a/src/commands/blame.ts b/src/commands/blame.ts
|
|
309
|
+
new file mode 100644
|
|
310
|
+
index 0000000..1234567
|
|
311
|
+
--- /dev/null
|
|
312
|
+
+++ b/src/commands/blame.ts
|
|
313
|
+
@@ -0,0 +1,315 @@
|
|
314
|
+
+import path from 'node:path'
|
|
315
|
+
+import readline from 'node:readline'
|
|
316
|
+
...
|
|
317
|
+
|
|
318
|
+
--- Actions ---
|
|
319
|
+
[n] Next commit [p] Previous commit [j] Jump [q] Quit
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**Use Cases:**
|
|
323
|
+
|
|
324
|
+
- 📖 **Code Review**: Understand how a file evolved over time
|
|
325
|
+
- 🐛 **Bug Investigation**: Find when a specific line was changed
|
|
326
|
+
- 📚 **Learning**: Study the development history of a feature
|
|
327
|
+
- 🔍 **Audit**: Review all changes made to a critical file
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
### Git History Viewer (`ng hist` / `ng history`)
|
|
332
|
+
|
|
333
|
+
Display git history with an interactive, scrollable graph view.
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
# Show full git history
|
|
337
|
+
ng hist
|
|
338
|
+
|
|
339
|
+
# Limit number of commits
|
|
340
|
+
ng hist -n 20
|
|
341
|
+
ng hist --number 50
|
|
342
|
+
|
|
343
|
+
# Using alias
|
|
344
|
+
ng history
|
|
345
|
+
ng history -n 10
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Features:**
|
|
349
|
+
- ✅ **Beautiful Graph Format**: Visualizes branch structure with commit tree
|
|
350
|
+
- ✅ **Interactive Navigation**: Scroll through history with keyboard or mouse
|
|
351
|
+
- ✅ **Optimized Display**: Automatically adjusts to terminal size
|
|
352
|
+
- ✅ **Status Bar**: Shows current position and available shortcuts
|
|
353
|
+
- ✅ **Color-Coded Output**:
|
|
354
|
+
- Cyan: Commit hash
|
|
355
|
+
- Green: Commit date
|
|
356
|
+
- Magenta: Author name
|
|
357
|
+
- Yellow: Branch references
|
|
358
|
+
|
|
359
|
+
**Interactive Controls:**
|
|
360
|
+
|
|
361
|
+
| Key | Action | Description |
|
|
362
|
+
|-----|--------|-------------|
|
|
363
|
+
| `↑` / `k` | Scroll up | Move up through commits |
|
|
364
|
+
| `↓` / `j` | Scroll down | Move down through commits |
|
|
365
|
+
| `gg` | Jump to top | Go to the oldest commit |
|
|
366
|
+
| `G` | Jump to bottom | Go to the newest commit (Shift+G) |
|
|
367
|
+
| `Page Up` | Page up | Scroll up one page |
|
|
368
|
+
| `Page Down` | Page down | Scroll down one page |
|
|
369
|
+
| `q` / `Enter` | Quit | Exit the viewer |
|
|
370
|
+
|
|
371
|
+
**Display Information:**
|
|
372
|
+
|
|
373
|
+
Each commit shows:
|
|
374
|
+
- 🔖 Short commit hash (cyan, bold)
|
|
375
|
+
- 📅 Commit date and time (green)
|
|
376
|
+
- 👤 Author name (magenta)
|
|
377
|
+
- 🌿 Branch and tag references (yellow)
|
|
378
|
+
- 💬 Commit message
|
|
379
|
+
|
|
380
|
+
**Status Bar:**
|
|
381
|
+
|
|
382
|
+
```
|
|
383
|
+
↑↓/jk: Scroll | gg/G: Top/Bottom | PgUp/PgDn | q: Quit | Lines 1-42/150
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Layout Optimization:**
|
|
387
|
+
|
|
388
|
+
- Automatically calculates optimal view height based on terminal size
|
|
389
|
+
- Reserves space for UI elements (borders, status bar)
|
|
390
|
+
- Ensures minimum of 10 lines for content display
|
|
391
|
+
- Removes unnecessary margins for maximum content visibility
|
|
392
|
+
|
|
393
|
+
**Use Cases:**
|
|
394
|
+
|
|
395
|
+
- 📊 **Project Overview**: Quickly see commit history and branch structure
|
|
396
|
+
- 🔍 **Context Browsing**: Understand recent changes before switching branches
|
|
397
|
+
- 📝 **Review History**: Check recent commits before pulling or pushing
|
|
398
|
+
- 🎯 **Navigation**: Find specific commits in the history
|
|
399
|
+
|
|
400
|
+
**Example Output:**
|
|
401
|
+
|
|
402
|
+
```
|
|
403
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
404
|
+
│* abc123de 2026-02-06 14:54:23 [GaoZimeng] (HEAD -> main) │
|
|
405
|
+
││ refactor(git): main increase hist viewer height line │
|
|
406
|
+
│* 1a40997 2026-02-06 14:52:15 [GaoZimeng] │
|
|
407
|
+
││ feat(git): fetch remote branches before pull │
|
|
408
|
+
│* a3be508 2026-02-06 14:51:23 [GaoZimeng] │
|
|
409
|
+
││ refactor(git): change branch selection from search to select│
|
|
410
|
+
│* 172403f 2026-02-06 14:50:12 [GaoZimeng] │
|
|
411
|
+
││ feat(git): enhance merge command with commit customization │
|
|
412
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
413
|
+
│ ↑↓/jk: Scroll | gg/G: Top/Bottom | PgUp/PgDn | q: Quit | Lines │
|
|
414
|
+
│ 1-10/150 │
|
|
415
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
### Stash Operations (`ng stash` / `ng st`)
|
|
421
|
+
|
|
422
|
+
Advanced stash management.
|
|
423
|
+
|
|
424
|
+
#### Save Changes
|
|
425
|
+
|
|
426
|
+
```bash
|
|
427
|
+
# Save with default message
|
|
428
|
+
ng stash save
|
|
429
|
+
|
|
430
|
+
# Save with custom message
|
|
431
|
+
ng stash save "work in progress"
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
#### List Stashes
|
|
435
|
+
|
|
436
|
+
```bash
|
|
437
|
+
ng stash list
|
|
438
|
+
ng stash ls
|
|
439
|
+
ng stash l
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
**Features:**
|
|
443
|
+
- ✅ Shows all stash entries
|
|
444
|
+
- ✅ Displays changed files for each stash
|
|
445
|
+
- ✅ File count per stash
|
|
446
|
+
|
|
447
|
+
#### Pop Stashes
|
|
448
|
+
|
|
449
|
+
```bash
|
|
450
|
+
ng stash pop
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
**Features:**
|
|
454
|
+
- ✅ Multi-select support
|
|
455
|
+
- ✅ Pop multiple stashes at once
|
|
456
|
+
|
|
457
|
+
#### Drop Stashes
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
ng stash drop
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
**Features:**
|
|
464
|
+
- ✅ Multi-select support
|
|
465
|
+
- ✅ Drop specific stashes
|
|
466
|
+
|
|
467
|
+
#### Clear All Stashes
|
|
468
|
+
|
|
469
|
+
```bash
|
|
470
|
+
ng stash clear
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
#### Stash History
|
|
474
|
+
|
|
475
|
+
View persistent stash history with metadata.
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
# View last 10 records
|
|
479
|
+
ng stash history
|
|
480
|
+
ng stash his # Alias
|
|
481
|
+
ng stash h # Short alias
|
|
482
|
+
|
|
483
|
+
# Options
|
|
484
|
+
ng stash history --all # Show all records
|
|
485
|
+
ng stash history --active # Active stashes only (unused)
|
|
486
|
+
ng stash history --clean # Clean records older than 30 days
|
|
487
|
+
ng stash history --clean 60 # Clean records older than 60 days
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**Features:**
|
|
491
|
+
- ✅ **Semantic Naming**: Uses format `{operation}:{branch}@{timestamp}` (e.g., `pull:feature/test@2025-01-27-18-30-00`)
|
|
492
|
+
- ✅ **Persistent Tracking**: Maintains history even after stashes are popped or dropped
|
|
493
|
+
- ✅ **File Metadata**: Includes list of files changed in each stash
|
|
494
|
+
- ✅ **Status Tracking**: Tracks if stash is `active`, `popped`, or `dropped`
|
|
495
|
+
- ✅ **Auto Cleanup**: Keeps history manageable with configurable cleanup
|
|
496
|
+
|
|
497
|
+
**Display Format Example:**
|
|
498
|
+
```
|
|
499
|
+
📚 Stash History (3 records)
|
|
500
|
+
|
|
501
|
+
━━━ 📦 pull:feature/test@2025-01-27-18-30-00 ━━━
|
|
502
|
+
Operation: pull
|
|
503
|
+
Status: active
|
|
504
|
+
Branch: feature/test
|
|
505
|
+
Time: 2025-01-27, 18:30:00
|
|
506
|
+
Files (2):
|
|
507
|
+
• src/utils.ts
|
|
508
|
+
• src/index.ts
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
## Configuration
|
|
514
|
+
|
|
515
|
+
### Commitlint Integration
|
|
516
|
+
|
|
517
|
+
The commit command reads your `commitlint.config.*` file to provide type and scope options:
|
|
518
|
+
|
|
519
|
+
```javascript
|
|
520
|
+
// commitlint.config.js
|
|
521
|
+
module.exports = {
|
|
522
|
+
rules: {
|
|
523
|
+
'type-enum': [2, 'always', [
|
|
524
|
+
'feat', 'fix', 'docs', 'style', 'refactor',
|
|
525
|
+
'perf', 'test', 'build', 'ci', 'chore', 'revert'
|
|
526
|
+
]],
|
|
527
|
+
'scope-enum': [2, 'always', [
|
|
528
|
+
'git', 'shared', 'ai', 'ui', 'packages', 'mail'
|
|
529
|
+
]]
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
### Lint-staged Integration
|
|
535
|
+
|
|
536
|
+
The commit command automatically runs `lint-staged` before committing if it's available in your project.
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
## Example Workflows
|
|
541
|
+
|
|
542
|
+
### Daily Development Flow
|
|
543
|
+
|
|
544
|
+
```bash
|
|
545
|
+
# 1. Start working on a new feature
|
|
546
|
+
ng co -b
|
|
547
|
+
# Select: feature/PRIME-
|
|
548
|
+
# Enter: 1500
|
|
549
|
+
# Creates: feature/PRIME-1500
|
|
550
|
+
|
|
551
|
+
# 2. Make changes...
|
|
552
|
+
|
|
553
|
+
# 3. Commit with interactive wizard
|
|
554
|
+
ng commit
|
|
555
|
+
# Select files to stage
|
|
556
|
+
# Choose type: feat
|
|
557
|
+
# Choose scope: git
|
|
558
|
+
# Enter title: add new command
|
|
559
|
+
# Enter description (optional)
|
|
560
|
+
# Preview and confirm
|
|
561
|
+
# Optionally push
|
|
562
|
+
|
|
563
|
+
# 4. Pull latest changes
|
|
564
|
+
ng pull
|
|
565
|
+
# Select branch: main
|
|
566
|
+
# Choose mode: rebase
|
|
567
|
+
# Auto stash/pop handled
|
|
568
|
+
|
|
569
|
+
# 5. Push your work
|
|
570
|
+
ng push
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
### Switching Contexts Safely
|
|
574
|
+
|
|
575
|
+
```bash
|
|
576
|
+
# Working on feature A, need to switch to feature B
|
|
577
|
+
ng checkout
|
|
578
|
+
# Auto stashes your current changes
|
|
579
|
+
# Select: feature/PRIME-1500 (feature B)
|
|
580
|
+
# Changes are popped automatically after checkout
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
### Cleaning Up Old Branches
|
|
584
|
+
|
|
585
|
+
```bash
|
|
586
|
+
# Delete specific old branches
|
|
587
|
+
ng branch delete
|
|
588
|
+
# Select branches to delete
|
|
589
|
+
# See merge status and last commit time
|
|
590
|
+
# Confirm deletion
|
|
591
|
+
|
|
592
|
+
# Or clean all merged branches older than 1 month
|
|
593
|
+
ng branch clean
|
|
594
|
+
# Select: 1 month
|
|
595
|
+
# Review list
|
|
596
|
+
# Confirm deletion
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
### Investigating File History
|
|
600
|
+
|
|
601
|
+
```bash
|
|
602
|
+
# Understand how a file evolved over time
|
|
603
|
+
ng blame src/utils/date.ts
|
|
604
|
+
|
|
605
|
+
# Interactive navigation:
|
|
606
|
+
# - Press 'n' to see next commit
|
|
607
|
+
# - Press 'p' to go back to previous commit
|
|
608
|
+
# - Press 'j' to jump to commit 5/10
|
|
609
|
+
# - Press 'q' when done reviewing
|
|
610
|
+
|
|
611
|
+
# Each commit shows:
|
|
612
|
+
# - Full commit hash, author, date, message
|
|
613
|
+
# - Complete diff (what changed)
|
|
614
|
+
# - Current position (e.g., "Commit 3/10")
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
**Real-world scenarios:**
|
|
618
|
+
|
|
619
|
+
- 🐛 **Bug Investigation**: Find when a bug was introduced
|
|
620
|
+
```bash
|
|
621
|
+
ng blame src/auth/login.ts
|
|
622
|
+
# Press 'n' repeatedly to review changes chronologically
|
|
623
|
+
# Look for the commit that broke the functionality
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
- 📖 **Code Review**: Understand the evolution of a complex function
|
|
627
|
+
```bash
|
|
628
|
+
ng blame src/api/handlers.ts
|
|
629
|
+
# Navigate through commits to see how the logic developed
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
- 🔍 **Audit Trail**: Review all changes to a security-critical file
|
|
633
|
+
```bash
|
|
634
|
+
ng blame src/config/security.ts
|
|
635
|
+
# Use 'j' to jump to specific commits of interest
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
---
|
|
639
|
+
|
|
640
|
+
### Browsing Project History
|
|
641
|
+
|
|
642
|
+
```bash
|
|
643
|
+
# View full git history with beautiful graph
|
|
644
|
+
ng hist
|
|
645
|
+
|
|
646
|
+
# View last 20 commits
|
|
647
|
+
ng hist -n 20
|
|
648
|
+
|
|
649
|
+
# Interactive navigation:
|
|
650
|
+
# - Use ↑/↓ or j/k to scroll through commits
|
|
651
|
+
# - Press 'gg' to jump to oldest commit
|
|
652
|
+
# - Press 'G' (Shift+G) to jump to newest commit
|
|
653
|
+
# - Use Page Up/Down to scroll by pages
|
|
654
|
+
# - Press 'q' or Enter to exit
|
|
655
|
+
|
|
656
|
+
# Features:
|
|
657
|
+
# - Color-coded output (hash, date, author, branches)
|
|
658
|
+
# - Visual commit graph showing branch structure
|
|
659
|
+
# - Status bar showing current position
|
|
660
|
+
# - Automatically adjusts to terminal size
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
**Real-world scenarios:**
|
|
664
|
+
|
|
665
|
+
- 📊 **Before Pulling**: Check what's been committed recently
|
|
666
|
+
```bash
|
|
667
|
+
ng hist -n 10
|
|
668
|
+
# Review recent commits before doing `ng pull`
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
- 🎯 **Finding Commits**: Locate a specific commit in history
|
|
672
|
+
```bash
|
|
673
|
+
ng hist
|
|
674
|
+
# Press 'gg' to go to oldest commit
|
|
675
|
+
# Use ↓/j to scroll forward to find what you need
|
|
676
|
+
# Note the commit hash (e.g., abc123de)
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
- 🌿 **Branch Overview**: Understand branch structure and merges
|
|
680
|
+
```bash
|
|
681
|
+
ng hist -n 50
|
|
682
|
+
# See how branches diverged and merged
|
|
683
|
+
# Identify branch points and merge commits
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
---
|
|
687
|
+
|
|
688
|
+
## Comparison: Git vs `ng`
|
|
689
|
+
|
|
690
|
+
| Operation | Git Command | `ng` Command |
|
|
691
|
+
|-----------|--------------|---------------|
|
|
692
|
+
| Commit | `git commit` | `ng commit` (interactive with lint) |
|
|
693
|
+
| Pull | `git pull` | `ng pull` (auto stash + mode selection) |
|
|
694
|
+
| Push | `git push` | `ng push` (interactive) |
|
|
695
|
+
| Checkout | `git checkout` | `ng checkout` (auto stash + interactive) |
|
|
696
|
+
| Branch delete | `git branch -D` | `ng branch delete` (merge status check) |
|
|
697
|
+
| List branches | `git branch` | `ng list` (enhanced display) |
|
|
698
|
+
| Merge | `git merge` | `ng merge` (auto stash + searchable) |
|
|
699
|
+
| Stash | `git stash` | `ng stash` (enhanced management) |
|
|
700
|
+
| Blame | `git blame` (line-by-line) | `ng blame` (full commit history with diff) |
|
|
701
|
+
| Log/History | `git log` (static output) | `ng hist` (interactive graph viewer) |
|
|
702
|
+
|
|
703
|
+
**Key Difference - `ng blame` vs `git blame`:**
|
|
704
|
+
|
|
705
|
+
| Feature | `git blame` | `ng blame` |
|
|
706
|
+
|---------|-------------|------------|
|
|
707
|
+
| Shows | Line-by-line annotations | Full commit history with diffs |
|
|
708
|
+
| Navigation | Scroll through file | Interactive commit navigation (n/p/j/q) |
|
|
709
|
+
| Diff View | No (use separately) | Yes, included for each commit |
|
|
710
|
+
| File Renames | Limited | Full support with `--follow` |
|
|
711
|
+
| Best For | Finding who changed a line | Understanding file evolution |
|
|
712
|
+
|
|
713
|
+
---
|
|
714
|
+
|
|
715
|
+
## Requirements
|
|
716
|
+
|
|
717
|
+
- Node.js `^20.19.0` or `>=22.12.0`
|
|
718
|
+
- Git installed and available in PATH
|
|
719
|
+
|
|
720
|
+
## License
|
|
721
|
+
|
|
722
|
+
ISC © [gaozimeng](https://github.com/GaoZimeng0425)
|