Git Commit
The git commit
command takes a snapshot of the current changes in the staging area.
Before executing the git commit
command, the git add
command is used to stage changes that will be saved after a commit.
The git commit
command is used to move changes from the Staging Area to the git repository.
It's a good practice to make new commits often, based on logical units of change.
Git commit
The git commit
command creates a commit and generates a commit-id. When we use the commit command without any argument,
it will open the default text editor and ask for the commit message.
The command will run as follows:
$ git commit
The command above will prompt a default editor and ask for a commit message.
Git commit -m
The git commit
command offers the option -m
that includes the commit message simultaneously through the command line.
The -m
option will not prompt a text editor.
The command to write the commit message on the line command will run as follows:
$ git commit -m "Your commit message"
Git commit -a
The git commit
command support -a
option that allows skipping the Staging Area. It will automatically stage any files that are already tracked by Git (New files will not be included).
The command to skip the staging area and commit files will run as follows:
$ git commit -a
We can combine the option -a
with -m
. This combination will allow skipping the staging area for already tracked files,
and it will use the command line for the commit message.
The command will run as follows:
$ git commit -ma
Git commit --amend
The git commit --amend
changes the most recent commit on the current branch. This command will be useful for commits
that haven't been pushed to the remote yet, and you want to change the content, or the commit message.
The command will run as follows:
$ git commit -amend