This article covers how to use the command 'Git Commit'
Previously we've looked at git add, where we separated the changes (i.e., staged) we wanted to keep from the changes we didn't.
To save these staged changes to our local repository, we need to commit them, along with a (hopefully) useful commit message:
git commit -m <commit-message>
Where -m is the message parameter.
If you also want to automatically add all changes of tracked files at the same time as committing, you can use the -a parameter:
git commit -a -m <commit-message>
Note: Tracked files are those that have previously been added. Any new files will not be added using the -a parameter with git commit.
Now let's say you committed, but left an unfortunate typo in the error message. You can amend your most recent commit message with the --amend parameter:
git commit --amend -m <commit-message>
Another problem you may have is that you've committed, but forgot to track a file first! You could commit on top of that, or you could just amend the previous commit. This command will amend the previous commit, whilst keeping the commit message the same, using the --no-edit parameter:
git commit --amend --no-edit
Finally, it may be useful to specify the author of the commit (if it's different from the default in your git config). You can do so with the --author parameter:
git commit -m <commit-message> --author="Author Name <email@example.com>"
If you forgot to do this before committing, simply combine it with --amend and --no-edit:
git commit --amend --no-edit --author="Author Name <firstname.lastname@example.org>"