Suggest an editImprove this articleRefine the answer for “What is git diff used for?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`git diff`** is used to view differences (changes) between file versions: before a commit, after a commit, or between commits/branches. **Key point:** the command shows exactly what changed, not just that something changed.Shown above the full answer for quick recall.Answer (EN)Image`git diff` is used to **view differences (changes) between file versions**: before a commit, after a commit, or between commits/branches. Simply put: the command shows **exactly what changed**, not just *that something changed*. ## What `git diff` shows by default ```bash git diff ``` Shows: - differences **between the working directory and the staging area** - changes that **have not yet been added** via `git add` --- ## Main use cases ### Difference between the staging area and the last commit ```bash git diff --staged # or git diff --cached ``` --- ### All changes (both staged and unstaged) ```bash git diff HEAD ``` --- ### Difference between two commits ```bash git diff commit1 commit2 ``` --- ### Difference between branches ```bash git diff main feature/login ``` --- ### Changes in a specific file ```bash git diff src/app.js ``` --- ## How to read `git diff` output ```diff - const a = 1; + const a = 2; ``` - `-` - a removed line - `+` - an added line - no sign - context --- ## Why `git diff` is used in practice - Check code **before** `git add` - Deliberately shape commits - Find the source of a bug - Do a code review locally - Compare implementations --- ## Frequent mistakes - Confusing `git diff` and `git status` - Not checking changes before a commit - Committing "blindly" --- ## Short version for an interview > `git diff` **is used to view differences between file versions - in the working directory, staging area, commits, or branches.**For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.