0
0
Gitdevops~5 mins

git diff for working directory changes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you change files but haven't saved those changes to your project history yet. You need a way to see exactly what you changed before saving. The git diff command shows the differences between your current files and the last saved version.
When you want to review what you changed in a file before saving those changes.
When you accidentally modified a file and want to see what was changed.
When you want to check which lines you added or removed in your working files.
When you want to compare your current files to the last saved snapshot in git.
When you want to prepare what to save by seeing the exact changes.
Commands
This command shows the differences between your current working files and the last saved commit. It helps you see what you changed but haven't saved yet.
Terminal
git diff
Expected OutputExpected
diff --git a/example.txt b/example.txt index e69de29..4b825dc 100644 --- a/example.txt +++ b/example.txt @@ -0,0 +1,2 @@ +Hello world +This is a new line
This command shows the same differences but with colors to make added and removed lines easier to see.
Terminal
git diff --color
Expected OutputExpected
diff --git a/example.txt b/example.txt index e69de29..4b825dc 100644 --- a/example.txt +++ b/example.txt @@ -0,0 +1,2 @@ +Hello world +This is a new line
--color - Shows differences with color highlighting for easier reading
Key Concept

If you remember nothing else from this pattern, remember: git diff shows what you changed in your files before saving those changes.

Common Mistakes
Running git diff after saving changes with git add
git diff then shows no output because it compares working files to the last commit, but staged changes are not shown here.
Use git diff to see unstaged changes, or git diff --staged to see staged changes.
Expecting git diff to show changes for untracked new files
git diff only shows changes to files already tracked by git, not new untracked files.
Use git status to see untracked files, and git add to start tracking them.
Summary
git diff shows the changes in your working files compared to the last saved commit.
Use git diff before saving to review what you changed.
git diff does not show staged or untracked files by default.