Git commit command

When we add a file in Git, it will take place in the staging area. The git commit command is used to record the updates from the staging area to the git repository. This command changes the HEAD. It records or snapshots the file permanently in the version history with a message.

Bash

git commit

The above command will prompt a default text editor and ask for a commit message.

Also, we can specify the commit message directly with the command itself.

Bash

git commit -m " Commit Message"

The above command will make a commit with the given commit message.

git commit --amend

The git commit --amend command is a convenient way to modify the most recent commit. It lets us combine staged changes with the previous commit instead of creating an entirely new commit. By using git commit --amend we can also edit the commit message of the last commit. It will run as follows:

Bash

git commit --amend

The above command will prompt the default text editor and allow us to edit the commit message.

Your image is not available

We can use the --no-edit option with the --amend option in git commit command to use the same commit message without launching an editor.

Bash

git commit --amend --no-edit