How to commit only modified (and not new or deleted) files?

git status shows a bunch of files which were modified and some which were deleted. I want to first commit the modified files and then the deleted ones. I don't see any option in git add that enables me to do this. How can I do it?

EDIT: As pointed out, git add wouldn't have staged the deleted files anyway, so git add . would do. But it has the side-effect of including files which weren't tracked, which I would also like to avoid. I have changed the title of the question accordingly.


Solution 1:

The following command should do the trick:

git commit -a

or

git commit -am "commit message"

From the Pro Git book:

Providing the -a option to the git commit command makes Git automatically stage every file that is already tracked before doing the commit

Solution 2:

git diff --name-only --diff-filter=M | xargs git add

(based on Charles Bailey's answer on a related question)

Solution 3:

You could use:

git add -u

to stage already tracked files that have been modified since last commit.

From git-add man page:

-u
--update

Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed. If no is given, default to "."; in other words, update all tracked files in the current directory and its subdirectories.

Not sure when this feature has been added though.