Skip to content

Commit 90d5118

Browse files
feat: add advanced usage examples and improve documentation
- Add comprehensive examples for CLI usage - Document programmatic usage patterns - Add CI/CD integration examples - Expand troubleshooting section - Update gitExclusions with common patterns
1 parent fee5d61 commit 90d5118

File tree

4 files changed

+111
-74
lines changed

4 files changed

+111
-74
lines changed

README.md

Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ A powerful CLI tool that generates beautifully formatted markdown files from git
1010

1111
So GitHub/GitLab/Bitbucket diff views works for you? Well good for you! But sometimes those remote git providers might be not your remote git provider and/or your diff view from your remote git providers might be not so friendly moreover if you have to review big changes (at least for your eyes). This tool simply offers an alternative that lets you:
1212

13-
- Generate clean, readable diffs when your remote git provider diff views are unavailable or unfriendly
14-
- Work completely offline - only needs internet access when comparing remote branches
15-
- Export diffs as markdown to attach to tickets, docs, or discussions
16-
- Share diffs with AI/LLM tools (ChatGPT, Claude, Copilot, etc.) to streamline code review, get suggestions, and catch potential issues
17-
- Automatically filter out noise like lockfiles and build artifacts
18-
- Create permanent documentation snapshots of important changes
19-
- Share diffs easily with any stakeholders
20-
- Use your IDE/editor's search and navigation features to analyze the generated diffs:
21-
- Search across all diff files to find specific changes
22-
- Use "Find in Files" to locate impacted code patterns
23-
- Leverage file tree navigation to browse changes by directory
24-
- Take advantage of markdown preview to view formatted diffs
25-
- Use split view to compare original and modified code side by side
26-
- Bookmark key changes for later review
13+
- Generate clean, readable diffs when GitHub/GitLab/Bitbucket or any other git provider diff views are unavailable or hard to use
14+
- Work offline - only requires internet for comparing remote branches
15+
- Export diffs as markdown files to:
16+
- Attach to tickets and documentation
17+
- Share with AI tools (ChatGPT, Claude, etc.) for code review assistance
18+
- Create permanent snapshots of important changes
19+
- Share easily with stakeholders
20+
- Smart filtering of noise like lockfiles and build artifacts
21+
- Editor-agnostic - works with any tool that supports markdown
22+
- Leverage your IDE's features to analyze diffs:
23+
- Full-text search across all changes
24+
- "Find in Files" for code patterns
25+
- File tree navigation by directory
26+
- Markdown preview for formatted diffs
27+
- Side-by-side diff comparison
28+
- Bookmarking for later review
2729

2830

2931
## Features
@@ -54,51 +56,78 @@ npm install -g git-markdown-diff
5456

5557
### Basic Usage
5658

57-
To generate diffs between your working tree and the last commit:
59+
Generate diffs between your working tree and the last commit:
5860

5961
```bash
6062
git-markdown-diff
6163
```
6264

6365
### Comparing Specific References
6466

65-
To generate diffs between specific git references (commits, branches, or tags):
67+
Compare changes between any git references (commits, branches, or tags):
6668

6769
```bash
68-
git-markdown-diff --start-ref <startRef> --end-ref <endRef>
70+
git-markdown-diff --start-ref <ref> --end-ref <ref>
6971
```
7072

7173
Examples:
7274
```bash
7375
# Compare between two commits
7476
git-markdown-diff -s abc123 -e def456
7577

76-
# Compare between branches
77-
git-markdown-diff --start-ref main --end-ref feature/new-feature
78+
# Compare between branches (changes in feature branch)
79+
git-markdown-diff -s feature/branch -e main
7880

79-
# Compare between tags
80-
git-markdown-diff -s v1.0.0 -e v1.1.0
81+
# Compare between tags (changes from v1.0.0 to v1.1.0)
82+
git-markdown-diff -s v1.1.0 -e v1.0.0
83+
84+
# Compare with remote branch
85+
git-markdown-diff -s origin/main -e main
86+
87+
# Compare staged changes
88+
git-markdown-diff -s HEAD -e --staged
8189
```
8290

8391
### Configuration Options
8492

8593
```bash
8694
Options:
87-
-s, --start-ref <ref> Starting reference (commit hash, branch name, or tag)
88-
-e, --end-ref <ref> Ending reference (commit hash, branch name, or tag)
95+
-s, --start-ref <ref> Starting reference (newer state)
96+
-e, --end-ref <ref> Ending reference (older state)
8997
-o, --output <dir> Output directory (default: "git-diffs")
90-
--exclude <patterns> Additional file patterns to exclude
98+
--exclude <patterns...> Additional file patterns to exclude
9199
-f, --format <format> Diff format: diff, unified, side-by-side (default: "diff")
92100
--light-mode Use light mode theme instead of dark mode
93101
-h, --help Display help
102+
```
94103

95-
# Examples:
96-
git-markdown-diff -s main -e develop -o custom-diffs # Custom output directory
97-
git-markdown-diff --exclude "*.log" "*.tmp" # Exclude additional files
98-
git-markdown-diff -s HEAD -e HEAD~1 -f side-by-side # Side-by-side diff format
99-
git-markdown-diff -s v1.0 -e v2.0 --light-mode # Light mode theme
104+
### Advanced Examples
105+
106+
```bash
107+
# Custom output directory with side-by-side diffs
108+
git-markdown-diff -s main -e develop -o pr-123-diffs -f side-by-side
109+
110+
# Exclude specific files/patterns
111+
git-markdown-diff --exclude "*.test.js" "docs/**" "*.md"
112+
113+
# Compare specific commit range with unified diff
114+
git-markdown-diff -s HEAD -e HEAD~5 -f unified
115+
116+
# Light mode theme with custom output
117+
git-markdown-diff -s release -e main --light-mode -o release-diffs
118+
119+
# Multiple options combined
120+
git-markdown-diff \
121+
-s feature/new-ui \
122+
-e develop \
123+
-o ui-changes \
124+
-f side-by-side \
125+
--exclude "*.test.js" "*.snap" \
126+
--light-mode
100127
```
101128

129+
> **Note**: The order of refs matters! Use `-s` for the newer state and `-e` for the older state to get the correct diff direction.
130+
102131
### Programmatic Usage
103132

104133
```javascript
@@ -179,11 +208,11 @@ The tool creates a `git-diffs` directory with the following structure:
179208

180209
```
181210
git-diffs/
182-
├── README.md # Index file with summary and links
183-
├── src/ # Mirrors your repository structure
184-
│ ├── file1.js.md # Diff for file1.js
211+
├── DIFF_INDEX.md # Index file with summary and links
212+
├── src/ # Mirrors your repository structure
213+
│ ├── file1.js.md # Diff for file1.js
185214
│ └── components/
186-
│ └── Component.js.md # Diff for Component.js
215+
│ └── Component.js.md # Diff for Component.js
187216
└── ...
188217
```
189218

@@ -230,11 +259,11 @@ The tool automatically excludes common files that typically don't need diff revi
230259

231260
Future improvements under consideration:
232261

233-
- [ ] Custom output directory option
262+
- [x] Custom output directory option
234263
- [ ] HTML export option
235264
- [ ] Integration with CI/CD pipelines
236-
- [ ] Custom exclusion patterns
237-
- [ ] Multiple diff format support
265+
- [x] Custom exclusion patterns
266+
- [x] Multiple diff format support
238267
- [ ] Interactive mode for file selection
239268

240269
## Contributing
@@ -300,8 +329,15 @@ This tool uses several open-source packages:
300329
- Ensure you're in a git repository
301330
- Check if git is installed: `git --version`
302331
- Verify git is configured: `git config --list`
332+
- On Windows, ensure paths don't contain special characters
303333

304334
2. **No output generated**
305335
- Verify you have changes to diff
306-
- Check if files are excluded by default patterns
307-
- Try specifying explicit commit ranges
336+
- Check if files are excluded by default patterns (see Excluded Files section)
337+
- Try specifying explicit commit ranges
338+
- Ensure your git range is correct (e.g., `master..feature` vs `feature..master`)
339+
340+
3. **Exclusion patterns not working**
341+
- Use forward slashes (/) even on Windows
342+
- Wildcards need proper escaping: `\*.log` or `"*.log"`
343+
- For directories, use `dir/**` to exclude all subdirectories

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "git-markdown-diff",
3-
"version": "0.0.40",
3+
"version": "0.0.41",
44
"description": "Git diff tool that outputs markdown formatted diffs",
55
"main": "src/sdk/GitMarkdownDiff.js",
66
"bin": {

src/sdk/constants/gitExclusions.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
const EXCLUSIONS = [
22
// Package manager locks
3-
":!package-lock.json",
4-
":!yarn.lock",
5-
":!pnpm-lock.yaml",
6-
":!npm-shrinkwrap.json",
7-
":!package-lock.linux-x64.json",
8-
":!package-lock.macos-arm64.json",
9-
":!package-lock.windows-x64.json",
3+
"package-lock.json",
4+
"yarn.lock",
5+
"pnpm-lock.yaml",
6+
"npm-shrinkwrap.json",
7+
"package-lock.linux-x64.json",
8+
"package-lock.macos-arm64.json",
9+
"package-lock.windows-x64.json",
1010
// Dependencies
11-
":!node_modules/*",
12-
":!vendor/*",
11+
"node_modules/**",
12+
"vendor/**",
1313
// Build outputs
14-
":!dist/*",
15-
":!build/*",
16-
":!out/*",
17-
":!.next/*",
18-
":!coverage/*",
19-
":!.nuxt/*",
14+
"dist/**",
15+
"build/**",
16+
"out/**",
17+
".next/**",
18+
"coverage/**",
19+
".nuxt/**",
2020
// IDE and OS files
21-
":!.idea/*",
22-
":!.vscode/*",
23-
":!*.suo",
24-
":!*.ntvs*",
25-
":!*.njsproj",
26-
":!*.sln",
27-
":!.DS_Store",
21+
".idea/**",
22+
".vscode/**",
23+
"*.suo",
24+
"*.ntvs*",
25+
"*.njsproj",
26+
"*.sln",
27+
".DS_Store",
2828
// Logs
29-
":!*.log",
30-
":!logs/*",
31-
":!npm-debug.log*",
32-
":!yarn-debug.log*",
33-
":!yarn-error.log*",
29+
"*.log",
30+
"logs/**",
31+
"npm-debug.log*",
32+
"yarn-debug.log*",
33+
"yarn-error.log*",
3434
// Environment and secrets
35-
":!.env*",
36-
":!*.pem",
37-
":!*.key",
35+
".env*",
36+
"*.pem",
37+
"*.key",
3838
// Generated files
39-
":!*.min.js",
40-
":!*.min.css",
41-
":!*.map",
42-
].join(" ");
39+
"*.min.js",
40+
"*.min.css",
41+
"*.map"
42+
];
4343

4444
module.exports = EXCLUSIONS;

src/sdk/utils/gitUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const gitUtils = {
1414
},
1515

1616
async getChangedFiles(range, exclusions) {
17+
const excludePatterns = exclusions.map(pattern => `:(exclude)${pattern}`).join(' ');
1718
const { stdout: filesOutput } = await execAsync(
18-
`git diff ${range} --name-only -- . ${exclusions}`,
19+
`git diff ${range} --name-only -- . ${excludePatterns}`,
1920
{ maxBuffer: 10 * 1024 * 1024 }
2021
);
2122
return filesOutput.split("\n").filter(Boolean);

0 commit comments

Comments
 (0)