Git working tree and merge conflict inspection cheat sheet
Separate staged, unstaged, untracked and conflicted files before choosing a commit or recovery action.
Git CLI in an existing trusted repository. These commands inspect local state without fetching, resetting or resolving conflicts.
Updated · Git · 6 min read
| Command | What it does |
|---|---|
git status --short --branch | Summarize the branch and file states |
git diff --stat | Measure unstaged tracked changes |
git diff --cached --stat | Measure changes staged for the next commit |
git diff --name-only --diff-filter=U | List unresolved conflict paths |
git ls-files -u -- src/app.js | Inspect unmerged index stages for one file |
git log -5 --oneline --decorate | Locate the current commit in recent history |
Walkthrough
Run from the affected checkout. Replace src/app.js with a real conflicted path. Remote-tracking information can be stale until a separately approved fetch; preserve local changes before planning recovery.
Step 1: Summarize the branch and file states
git status --short --branch
Read the two status columns separately: the first describes the index and the second the working tree, with special combinations for conflicts. Untracked files appear separately. Upstream ahead/behind counts depend on the last locally known remote state.
Step 2: Measure unstaged tracked changes
git diff --stat
This summarizes differences between tracked working files and the index. It excludes staged-only changes and untracked files, so a blank result does not mean the checkout is clean. Compare it with status before concluding that work is missing.
Step 3: Measure changes staged for the next commit
git diff --cached --stat
Inspect what the index contains relative to HEAD. A file can have both staged and unstaged edits; compare both diff summaries. The staged snapshot is what a normal commit records, not necessarily the entire current file on disk.
Step 4: List unresolved conflict paths
git diff --name-only --diff-filter=U
Collect paths with unmerged index entries before editing. The list does not determine which side is correct or whether a merge versus rebase is in progress; read the full status message for the operation and its next steps.
Step 5: Inspect unmerged index stages for one file
git ls-files -u -- src/app.js
Read the stage numbers and object IDs. For a typical content conflict, stages 1, 2 and 3 represent base and the two sides; add/delete conflicts can omit stages. During a rebase, intuitive meanings of ours and theirs can differ from a normal merge.
Step 6: Locate the current commit in recent history
git log -5 --oneline --decorate
Compare HEAD and visible branch labels with the expected checkout. This shows local history, not evidence that a push succeeded. Detached HEAD can be intentional in CI or inspection work; do not move branch pointers just to change its appearance.
WORKED INCIDENT
Practical case: A file seems missing from the next commit
Fictional teaching scenario; observations are examples, not captured production output.
Situation
A developer edits several files during a merge, but the staged diff contains only part of the work.
Investigation sequence
1. Summarize the branch and file states
git status --short --branchRead the status columns and identify files with both staged and unstaged changes.
2. Measure unstaged tracked changes
git diff --statCompare the unstaged summary with the intended change; an edited file can be absent from the staged snapshot.
3. Measure changes staged for the next commit
git diff --cached --statInspect the actual staged file set rather than assuming every visible editor change will be committed.
4. List unresolved conflict paths
git diff --name-only --diff-filter=UCheck for unresolved paths before recommending a commit or proceeding with the merge.
Example findings
Illustrative findings: status reports MM for one file and UU for another; the staged summary omits the newest working-tree edit.
Interpret the findings
The index and working tree contain different snapshots, and a separate conflict remains unresolved. These are two issues; staging everything blindly would not establish that the conflict resolution is correct.
Verify the outcome
After reviewing and resolving the intended edits, repeat status and both diffs. Verify the staged patch contains only the approved change and that no unmerged paths remain before committing.
Escalation handoff
Provide the branch, operation in progress, affected paths and relevant patch excerpts to the repository owner. Preserve the checkout; avoid reset or clean as a diagnostic shortcut.