Sobes.tech
Senior

What is the purpose of the --amend flag in the git commit --amend command?

sobes.tech AI

Answer from AI

The --amend flag in the git commit --amend command is used to modify the last commit. It allows you to correct the commit message, add forgotten changes, or remove unnecessary files from the last commit without creating a new one.

Example of usage:

git add corrected_file
# then amend the last commit, adding changes and/or changing the message
 git commit --amend -m "New commit message"

It is important to remember that if the commit has already been pushed to a shared repository, changing it with --amend can lead to conflicts during synchronization, so it should be used with caution.