Review new files in diffs with git add -N
When you create a new file, it can be awkward to review it in a diff-first workflow:
git statusclearly shows the untracked file.git diffoften shows nothing, because Git can only diff between two known states.
git add -N <path> fixes that by creating an empty index entry for the new file ("intent to add"). From then on, git diff can show the file as a normal patch without actually staging the contents.
Step by step
-
Confirm the file is untracked:
-
Mark the file as intent-to-add:
-
Review it as an unstaged diff:
-
If you want to undo the intent-to-add entry:
Variations
-
If you actually want to stage the full content of the new file, use
git add <path>. -
If you want to review what you already staged, use
git diff --staged.
Note: for intent-to-add paths, git diff --staged output can look surprising. That’s normal: the index entry is intentionally empty.
Common mistakes
- Mixing up
git diff(working tree vs index) withgit diff --staged(index vs HEAD). - Assuming
git add -Nstages file contents. It doesn’t.
See also
-
git statusfor spotting untracked files.