The git diff command has several options that allow you to customize its behavior and output. Here are some commonly used options:
-
Compare Working Directory with Staging Area:
git diffShows changes in the working directory that are not staged for the next commit.
-
Compare Staged Changes with Last Commit:
git diff --cachedShows changes that are staged for the next commit compared to the last commit.
-
Compare Two Commits:
git diff commit1 commit2Compares the differences between two specific commits.
-
Compare a Specific File:
git diff HEAD -- path/to/fileShows changes in a specific file compared to the last commit.
-
Ignore Whitespace Changes:
git diff -wIgnores whitespace changes when comparing files.
-
Show Differences in a Side-by-Side Format:
git diff -yDisplays the differences in a side-by-side format (note: this option may require additional tools).
-
Show Only Names of Changed Files:
git diff --name-onlyLists only the names of files that have changed.
-
Show Summary of Changes:
git diff --statProvides a summary of changes, including the number of lines added and removed.
-
Compare with a Specific Branch:
git diff branch_nameCompares the current branch with the specified branch.
-
Show Changes in a Specific Directory:
git diff path/to/directory/Shows changes in a specific directory.
These options can be combined to tailor the output of git diff to your specific needs. For example:
git diff --cached --name-only
This command will show the names of files that are staged for the next commit.
