git-range-diff - Linux
Overview
git-range-diff
is a versatile command that helps you compare changes between any two revisions, branches, or tags in a Git repository. It offers a detailed summary of the differences, including changed files, modifications to those files, and a compact diff view. This command is particularly useful for analyzing code contributions, reviewing code changes, and tracking the evolution of your project.
Syntax
git range-diff [<options>] <range> [<range>]
Required Arguments:
<range>
: Specifies the first revision or branch to compare.<range>
: Specifies the second revision or branch to compare.
Options/Flags
-b, --binary
: Compares the contents of binary files as hex dumps.-n, --numstat
: Displays a summary of the changes in a numstat format.-s, --shortstat
: Displays a short summary of the changes.-v, --verbose
: Outputs a detailed diff view of the changes.--color[=<when>]
: Colorizes the output. Possible values for<when>
are: always, never, or auto.-C<n>, --context=<n>
: Sets the context lines to display around the changes.-M<modename>, --rename-mode=<modename>
: Specifies the rename mode. Possible values for<modename>
are: copies, links, and full.
Examples
Compare changes between two commits:
git range-diff HEAD~3 HEAD
Compare changes between a branch and a tag:
git range-diff master v1.0
Display a numstat summary of changes:
git range-diff -n HEAD~3 HEAD
Colorize the output and display a detailed diff:
git range-diff -v --color=always HEAD~3 HEAD
Common Issues
- Empty Diff: If the specified revisions have no changes, the command will output an empty diff.
Integration
git-range-diff
can be combined with other Git commands to create powerful workflows. For example:
- Compare Changes from a Merge Request:
git fetch origin refs/merge-requests/123/merge
git range-diff origin/master FETCH_HEAD
- Generate a Diff for a Pull Request:
git stash
git checkout <remote-branch>
git range-diff local-branch...remote-branch
Related Commands
git diff
: Compares changes between two revisions.git log
: Shows the history of commits in a repository.git status
: Displays the current state of the working directory and staging area.