git diff --histogram
This command shows differences in your files using a smarter algorithm that tries to group related insertions and deletions in a way that is easier to read and understand.
This command compares the current state of your files to another state (like your last commit or another branch) and uses the --histogram flag to tell Git to use the “histogram” diff algorithm, which focuses on matching similar lines and producing cleaner hunks; without this flag, Git uses its default diff algorithm, which can sometimes show more noisy or less intuitive diffs. You can combine this with other flags like --stat to see a summary of changes, --name-only to list just the changed files, or --color (often enabled by default) to highlight additions and deletions. You can also pair --histogram with range or path arguments, for example git diff --histogram HEAD~1, git diff --histogram main..feature-branch, or git diff --histogram -- src/your_file.py, to focus on specific commits, branches, or files.
The histogram algorithm is especially useful when files have been heavily edited, reordered, or partially copied, because it tries to align similar content instead of only matching exact line positions, which often results in more readable diffs for refactors or large edits. If you need to adjust how the diff is displayed, you can add options like --word-diff to show changes at the word level or --unified=10 to show more context lines around each change while still using --histogram to compute the matching.
You can use similar algorithms such as git diff --patience for a more conservative but often very clean diff, or git diff --minimal if you want Git to spend more time finding the smallest possible set of changes, and you can compare them directly by running each variant on the same files to see which output is easier to understand. For quick overviews you might use git show --histogram to see the latest commit’s changes with the same algorithm, or git log -p --histogram to view a history of commits each with histogram-based diffs.