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:
git status -s
Display a short summary of the working directory's status
- Mark the file as intent-to-add:
- Review it as an unstaged diff:
- If you want to undo the intent-to-add entry:
git reset -- <path>
Unstage changes for the specified `path` while keeping the working-directory edits intact.
Variations
- If you actually want to stage the full content of the new file, use
git add <path>.
git add <path>
Stages changes in the specified <path> so they are included in the next commit.
- If you want to review what you already staged, use
git diff --staged.
git diff --staged
Displays changes between the index and the last commit.
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.
git status
Show the status of the current repository