Reputation: 4088
I often use git add -p
to commit files in pieces in Git, but that doesn't work for untracked files:
$ git add -p file
No changes.
How can I add this file, but not stage all of it?
I want to add only part of it and commit and leave the rest unstaged.
Upvotes: 5
Views: 1356
Reputation: 4088
You can do this in two steps:
git add -N file
From the man page:
-N, --intent-to-add
Record only the fact that the path will be added later. An entry for the path is placed in the index with no content. This is useful for, among other things, showing the unstaged content of such files withgit diff
and committing them withgit commit -a
.
This command will add the file empty, so it won't be untracked anymore, but none of it will be staged yet.
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: file
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file
#
git add -p file
Now the file is tracked and git add -p
works as it should.
Upvotes: 15