Skip to content

lropero/difflog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

difflog

Find a commit by fuzzy-searching git log and print its diff.

difflog is a small CLI helper for quickly finding a commit by message or hash and outputting the diff for that commit.

Usage

npx difflog [options] -- <search terms>

Example:

npx difflog -e package-lock.json -o diff.txt -u 999999 -- JIRA-123 mobile

This searches the Git history for a commit similar to:

JIRA-123 mobile

Then outputs the diff for the matched commit, excluding package-lock.json, using 999999 unified context lines, and saving the result to diff.txt.

Options

-b, --body                Include commit body in fuzzy search
-e, --exclude <path...>   Exclude one or more paths from the diff
-o, --output <file>       Write diff output to a file
-s, --stat                Output diff stat instead of the full patch
-u, --unified <lines>     Number of unified diff context lines

CLI messages (errors, the saved confirmation, ambiguous lists, and hints) are lightly colored for readability. The actual diff or stat is always raw Git output with no coloring, so it stays safe to pipe or redirect.

Output size in bytes is reported only when writing to a file with -o. When the diff or stat goes to stdout, nothing extra is printed before or after it.

Examples

Print a commit diff to stdout:

npx difflog -- JIRA-123 mobile

Save a commit diff to a file:

npx difflog -o diff.txt -- JIRA-123 mobile
# Saved diff for abc1234 -> JIRA-123 Fix mobile view to diff.txt (123456 bytes)

Show a diff stat instead of the full patch:

npx difflog -s -- JIRA-123 mobile

Save a diff stat to a file:

npx difflog -s -o stat.txt -- JIRA-123 mobile
# Saved stat for abc1234 -> JIRA-123 Fix mobile view to stat.txt (1234 bytes)

Combine excludes with a stat:

npx difflog -s -e package-lock.json -- JIRA-123 mobile

Include the commit body in the fuzzy search (matching beyond the subject):

npx difflog -b -- "rollback plan"

Exclude one file:

npx difflog -e package-lock.json -- JIRA-123 mobile

Exclude multiple files:

npx difflog -e package-lock.json yarn.lock pnpm-lock.yaml -- JIRA-123 mobile

Repeat -e:

npx difflog -e package-lock.json -e yarn.lock -- JIRA-123 mobile

Use a large unified context:

npx difflog -u 999999 -- JIRA-123 mobile

Search by short hash:

npx difflog -- abc1234

Search by full hash:

npx difflog -- abc1234567890abcdef1234567890abcdef12345678

Important: use -- before search terms

When using options, especially --exclude, pass search terms after --:

npx difflog -e package-lock.json -- JIRA-123 mobile

This prevents search terms from being interpreted as option values.

Matching behavior

difflog searches commit history using:

  • full commit hash
  • short commit hash
  • commit subject

With -b, --body, the commit body is also included in the search. -b only affects matching; it does not change the diff or stat output, and ambiguous match lists still show only the short hash and subject.

If there is one clear best match, it prints or saves that commit’s diff.

If multiple commits match similarly, difflog does not guess. It prints a ranked list and asks you to refine the search.

Example:

Multiple commits matched "mobile". Refine your search:
  1. abc1234  JIRA-123 Fix mobile view for tenant clients page
  2. def5678  JIRA-124 Improve mobile spacing in assessment form

Diff behavior

For normal commits, difflog outputs the equivalent of:

git diff <commit>^!

That means the output is a plain diff for the selected commit, without the commit header or commit message metadata included by git show.

For root commits, difflog compares the root commit against the repository’s empty tree, so the output shows what the first commit introduced.

Merge commits

Merge commits are not diffed automatically.

A merge commit can be interpreted in multiple ways, so difflog stops with a clear message instead of producing misleading output.

For merge commits, inspect the commit manually with Git:

git show <commit>
git show --first-parent <commit>

Requirements

  • Node.js >= 20
  • Git
  • Run from inside a Git repository

License

ISC

About

Find a commit by fuzzy-searching git log and printing its diff.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors