Is it better to use, instead, the "classic" two steps ?
The documentation of git commit
mentions no less than 5 ways to tell Git what you want to include in the next commit:
The content to be added can be specified in several ways:
- by using
git add
to incrementally "add" changes to the index before using the commit command (Note: even modified files must be "added");
- by using
git rm
to remove files from the working tree and the index, again before using the commit command;
- by listing files as arguments to the commit command (without
--interactive
or --patch
switch), in which case the commit will ignore changes staged in the index, and instead record the current content of the listed files (which must already be known to Git);
- by using the
-a
switch with the commit command to automatically "add" changes from all known files (i.e. all files that are already listed in the index) and to automatically "rm" files in the index that have been removed from the working tree, and then perform the actual commit;
- by using the
--interactive
or --patch
switches with the commit command to decide one by one which files or hunks should be part of the commit in addition to contents in the index, before finalizing the operation. See the "Interactive Mode" section of git-add
to learn how to operate these modes.
There are so many options not because some of them are "good" while others are "better". Git provides so many options to let you pick the one you prefer or the one that fits best in a specific situation.
For example, if you discover there is a modified file that should be part of the previous commit (but you forgot to commit it) and the index currently contains the files prepared for the next commit, using the first command from the question (option #3 in the list above) allows you to commit only that file without changing the index. This way the file you missed skips the line and is committed where it belongs, right after the previous commit, without interfering with the next commit you are preparing.