Getting Started Git Basics Diff
Diff
Learn what diffs show in Git, from unstaged and staged changes to commit and branch comparisons.
A diff is a comparison that shows what changed between two versions of a file or repository state.
Instead of showing the whole file from scratch, a diff focuses on the parts that were added, removed, or modified.
Why diffs matter
Diffs are one of the main ways people review work in Git.
They help you answer questions like:
- What exactly changed in this file?
- What have I changed but not staged yet?
- What is already staged for the next commit?
- What changed between two commits or branches?
Without diffs, Git history would be much harder to inspect and review.
Unstaged diffs
An unstaged diff compares your current worktree to the staged state.
This shows the changes you made locally that are not yet in the staging area.
Use an unstaged diff when you want to review your current edits before deciding whether to stage them.
Staged diffs
A staged diff compares the staged state to the last commit on your current branch.
This shows what would go into the next commit if you committed right now.
Use a staged diff when you want to verify that the next commit contains exactly what you intended.
Commit and branch diffs
Diffs are not only for uncommitted work.
Git can also show differences:
- Between two commits.
- Between two branches.
- Between your local branch and a remote branch.
That makes diffs useful for code review, troubleshooting, and understanding what changed over time.
How to read a diff
At a basic level:
- Added lines are shown as new content.
- Removed lines are shown as deleted content.
- Nearby unchanged lines are often included as context.
The exact colors and formatting depend on the tool, but the core idea is the same: a diff highlights what changed between two states.
Using diffs in GitComet
GitComet uses diffs to help you inspect changes safely before committing or synchronizing work.
For example, you can use diffs to:
- Review local edits file by file.
- Confirm what is staged.
- Inspect the contents of a commit.
- Understand why Git reports a file as changed.