git commit --amend
On this page you can find useful information about git commit --amend command, find out some ways of its usage, as well as see a few examples.
Definition and usage
While working with Git, you can often forget to format the commit or to stage a file. The git commit --amend command is the easiest way of correcting such mistakes. It is used to edit the latest commits. Instead of creating a completely new commit, you can run this command for combining staged changes with the previous commit. Besides, this command can modify the previous commit message without changing its snapshot. Take into account that git commit --amend replaces the current commit entirely. We will look at some ways to use git commit --amend.

Changing the most recent Git commit message
If you have committed and made a mistake in the commit log message, you can execute git commit --amend to modify the log message of the previous commit without changing its snapshot. You can pass in a new message from the command line without receiving a prompt for opening an editor by using the -m option.
git commit --amend
git commit --amend -m "an updated commit message"Changing committed files
Let’s imagine that you have modified some files that you want to commit in a singular snapshot, but you have forgotten to add one of the files the first time around. You can solve this problem if you stage the other file and commit by using the --amend flag. Add the --no-edit flag to modify your commit without changing the commit message. As a result, the wrong commit will be replaced by the right one, and the workflow will look like this:
git commit --amend --no-edit
# Modify project.py and text.py
git add project.py
git commit
# You forgot to add the changes from text.py
git add text.py
git commit --amend --no-editAvoid amending public commits
In fact, amended commits are new ones and after amending a commit, the previous commit will not be removed from the current branch. That’s why you should never amend a commit which is being developed by other team members because it will cause a lot of problems for collaboration. So you notice that the consequences are the same as in the case of resetting a public snapshot.
Practice
What are the correct statements about the " `git commit --amend` command as per the W3Docs Git Tutorial?