Skip to main content

git status & git diff โ€” Inspecting Changes

git statusโ€‹

git status shows the state of your working tree and index relative to the current HEAD commit.

git status # full output
git status -s # short/compact format
git status -b # include branch and tracking info

Reading the outputโ€‹

On branch feature/JIRA-123
Your branch is ahead of 'origin/feature/JIRA-123' by 2 commits.

Changes to be committed: โ† in the index (staged)
(use "git restore --staged <file>..." to unstage)
modified: src/main/java/com/example/TransactionService.java
new file: src/main/java/com/example/dto/ExportRequest.java

Changes not staged for commit: โ† in working tree, not staged
(use "git add <file>..." to update what will be committed)
modified: src/main/resources/application.yml

Untracked files: โ† new files Git doesn't know about
src/test/java/com/example/ExportServiceTest.java

Short formatโ€‹

git status -s
# M TransactionService.java โ† staged modification
# M application.yml โ† unstaged modification
# A dto/ExportRequest.java โ† staged new file
# ?? ExportServiceTest.java โ† untracked
SymbolMeaning
M (left column)Staged modification
M (right column)Unstaged modification
AStaged new file
DDeleted
RRenamed
??Untracked
!!Ignored

git diffโ€‹

git diff shows the actual line-by-line changes between states.

Unstaged changes (working tree vs index)โ€‹

git diff
# Shows what you've changed but NOT yet staged

Staged changes (index vs last commit)โ€‹

git diff --staged
# or:
git diff --cached
# Shows what WILL go into the next commit

Between two commitsโ€‹

git diff abc1234 def5678
git diff HEAD~3 HEAD
git diff v1.1.0 v1.2.0

Between two branchesโ€‹

git diff main feature/JIRA-123
git diff origin/main HEAD

A specific file onlyโ€‹

git diff HEAD -- src/main/java/com/example/TransactionService.java

Stat summary (no line detail)โ€‹

git diff --stat
git diff --stat main..feature/JIRA-123
# Output:
# src/main/java/.../TransactionService.java | 24 +++++++----
# src/main/java/.../ExportController.java | 51 +++++++++++++++++++++
# 2 files changed, 64 insertions(+), 11 deletions(-)

Word-level diff (easier to read for prose/config changes)โ€‹

git diff --word-diff

Reading a Diffโ€‹

diff --git a/src/main/java/com/example/TransactionService.java b/src/main/java/com/example/TransactionService.java
index 3b1f2c4..9a0e7f1 100644
--- a/src/main/java/com/example/TransactionService.java โ† old version
+++ b/src/main/java/com/example/TransactionService.java โ† new version
@@ -24,7 +24,10 @@ public class TransactionService { โ† hunk header

public Page<TransactionDto> findTransactions(...) {
- validateDateRange(fromDate, toDate); โ† removed line (red)
+ validateDateRange(fromDate, toDate); โ† added line (green)
+ log.debug("Fetching for userId={}", userId); โ† new line
return transactionRepository.findBy...
}
  • --- = the old (before) version
  • +++ = the new (after) version
  • @@ = hunk header showing line numbers
  • - lines = removed
  • + lines = added
  • Unchanged context lines have no prefix

Useful Flags Summaryโ€‹

diff flagsโ€‹

FlagMeaning
--staged / --cachedDiff index vs HEAD (what's staged)
--statSummary of files changed and line counts
--name-onlyOnly show filenames
--name-statusFilenames with M/A/D status
--word-diffHighlight changes at word level
--ignore-space-changeIgnore whitespace changes
-U<N>Show N lines of context (default 3)
--color-wordsColor-code word-level changes inline

Use Your IDE Diff Tool

For complex diffs, open your IDE's diff viewer. You can configure Git to use IntelliJ IDEA's diff tool:

git config --global diff.tool intellij
git config --global difftool.intellij.cmd 'idea diff "$LOCAL" "$REMOTE"'
git difftool HEAD~1

Interview Questions (Senior Level)โ€‹

  1. How do you establish a diff-review routine that catches risky changes early?
  2. When should reviewers insist on split commits based on status/diff output?
  3. What diff views are most useful for config-heavy versus code-heavy changes?
  4. How do you avoid whitespace-only noise masking critical logic edits?

Short answer guide:

  • Review staged and unstaged deltas separately before commit.
  • Split mixed-intent changes to improve safety and traceability.
  • Use word/stat/name-status modes based on change type.
  • Apply ignore-whitespace views carefully, then re-check full diff.
Interview Focus

Describe a practical diff-review checklist that catches risky changes before they reach PR.

Interview Trap

Relying on file names or summary stats without inspecting actual staged hunks.