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 --amend

Examples

Related commands

Practise · All commands