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
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
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
The above command will prompt the default text editor and allow us to edit the commit message.
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
After successfully amending the commit we can see that the commit id is changes from previous, as illustrated in the image below.