git-whatchanged - Linux
Overview
git-whatchanged is a powerful command used to quickly and easily identify changes made to files within a Git repository. It provides a concise overview of the differences between two commits, branches, or tags, highlighting the specific modifications made to each file. By providing a clear and structured breakdown of the changes, this tool significantly simplifies the process of reviewing code changes, tracking down issues, and understanding the evolution of a project.
Syntax
git whatchanged [options] <commit-ish>...
Options/Flags
-a, --all
– Display changes to all files, including untracked files.-c, --count
– Show only the number of changed lines in each file.-l, --lines
– Limit output to the specified number of lines per file.-m, --multiline
– Display multiline changes as a single line.-p, --patch
– Show diffs for each file.--no-commit-id
– Suppress commit IDs from the output.--no-header
– Suppress the header line containing the commit and branch information.
Examples
Show changes between two commits:
git whatchanged HEAD~1..HEAD
Display only the number of changed lines:
git whatchanged -c HEAD~1..HEAD
Limit output to 10 lines per file:
git whatchanged -l 10 HEAD~1..HEAD
Display diffs for all files:
git whatchanged -p HEAD~1..HEAD
Compare the current branch with the remote origin:
git whatchanged HEAD origin/main
Common Issues
Missing or incorrect commit-ish: Ensure that the specified commit-ish (commit, branch, or tag) is valid and exists in the repository.
No changes detected: Check if the specified commit-ish represents a genuine change in the codebase. If there are no actual changes, the command will not report any differences.
Unicode encoding issues: If non-ASCII characters are present in the file names or contents, ensure that the terminal or output device supports Unicode encoding.
Integration
Combine with grep
to filter changes:
git whatchanged HEAD~1..HEAD | grep 'my-function'
Use with diff
to create a patch file:
git whatchanged -p HEAD~1..HEAD | diff -u > my-patch.patch
Related Commands
git diff
– Show differences between two commits, branches, or tags.git status
– Display the status of the working tree and staging area.git log
– Show the history of commits in a repository.
For more detailed information and examples, refer to the Git documentation.