I want to commit a Python module’s
$ git add -N __init__.py
Record only the fact that the path will be added later. An entry for the path is placed in the index with no content.
will be added later
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
# new file: b
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# modified: b
$ git commit -m 'test'
b: not added yet
error: Error building trees
This should be fixed with Git 2.5 (Q2 2015), meaning
git commit won't try to include the new file "intended to be added later".
See commit d95d728 by Nguyễn Thái Ngọc Duy (
pclouds) (merged in d0c692263)
diff-lib.c: adjust position of
Entries added by "
git add -N" are reminder for the user so that they don't forget to add them before committing. These entries appear in the index even though they are not real.
Their presence in the index leads to a confusing "
git status" like this:
On branch master Changes to be committed: new file: foo Changes not staged for commit: modified: foo
If you do a "
git commit", "
foo" will not be included even though "
status" reports it as "
to be committed".
This patch changes the output to become
On branch master Changes not staged for commit: new file: foo no changes added to commit
In other words:
- Treat such paths as "yet to be added to the index but Git already know about them";
git diff HEAD" and "
git diff --cached HEAD" should not talk about them, and
git diff" should show them as new files yet to be added to the index.
Update Q4 2016:
commit: fix empty commit creation when there's no changes but ita entries
i-t-a is "intent to add")
When new paths were added by "
git add -N" to the index, it was enough to circumvent the check by "
git commit" to refrain from making an empty commit without "
The same logic prevented "
git status" to show such a path as "
new file" in the "
Changes not staged for commit" section.
git diff man page now includes:
By default entries added by "
git add -N" appear as an existing empty file in "
git diff" and a new file in "
git diff --cached".
This option makes the entry appear as a new file in "
git diff" and non-existent in "
git diff --cached".
This option could be reverted with
Both options are experimental and could be removed in future.