git commit
Save the staged changes to history as a new commit
What it does
A commit is a snapshot of the project with a message, an author and a date. git commit takes what is in the index and adds a new commit to the current branch. Pass the message with -m; without it git opens an editor.
-a stages every modified file git already tracks, so no separate git add is needed. It leaves new files alone. --amend replaces the last commit: use it to fix the message or add a forgotten file.
Careful. --amend replaces the last commit with a new one. If the old one is already on the server, the histories split and a plain git push fails. Do not amend commits other people already have.
Syntax
git commit -m "<message>"
git commit -am "<message>"
git commit --amendExamples
Commit the changes with the message fix: header
git commit -m "fix: header"same as:
git commit --message "fix: header",git commit -m 'fix: header'commit— record the staged changes-m— message right on the command line"fix: header"— message text
Commit every modified tracked file with the message update styles, without git add
git commit -am "update styles"same as:
git commit -a -m "update styles",git commit -am 'update styles'-a— first stage every modified tracked file-m— message"update styles"— message text
Change the last commit’s message to fix: header layout
git commit --amend -m "fix: header layout"same as:
git commit --amend --message "fix: header layout",git commit --amend -m 'fix: header layout'--amend— rewrite the last commit-m "fix: header layout"— new message