The Git Commit Command

After you made some changes, you want to commit them. By using the commit command, you create a new commit containing the current contents of the index and the given log message describing the changes. The contents to be committed can be specified in several ways.
Using the commit command after incrementally adding changes to the index
You can use the Git add command to incrementally add changes to the index. This simply means that you are using the git add command once or multiple times to add files to the index.
Using git rm to remove files from the working tree
Once you added files to the working tree, you might want to remove them from the working tree again. To do so, you can use the git rm command.
Listing all files as arguments to the commit command
You can list all files to be committed as arguments to the commit command. The resulting commit will ignore changes staged in the index and instead record the current content of the listed files. The files must already be known to Git, i.e. they have to have been added once before. This means, that newly created files cannot be committed by passing them as arguments to the commit command and will result in an error:
Instead, you would need to add them before by using the git add command:
Using the commit command with the -a switch
When using the -a switch with the commit command, Git will
- add changes from all known files (i.e. all files that are already listed in the index)
- remove files in the index that have been removed from the working tree
and then perform the actual commit.
Let’s assume that we have file1.txt and file2.txt in the index. Executing the commit command with the -a switch
will result in the following:
Reference
For full reference see Git commit documentation.