Forrest logo
back to the git tool

git-commit:tldr:a5c1b

git-commit: Update the last commit by adding the currently staged changes, changing the commit's hash.
$ git commit --amend
try on your machine

The command "git commit --amend" is used to modify the most recent commit in Git.

When you make a commit, Git creates a new snapshot of your project's current state and adds it to the commit history. However, sometimes you may realize that you forgot to include a file, made a typo in the commit message, or want to make some other changes to the commit. In such cases, you can use the "git commit --amend" command.

Here's what the command does:

  1. It opens your default text editor, displaying the last commit message. You can modify the commit message if desired.
  2. It allows you to make changes to the staging area (index) using "git add" or "git rm" commands. This means you can also add/remove files to/from the last commit.
  3. It creates a new commit with the modified changes, replacing the previous commit in the commit history. The new commit will have the same parent(s) as the previous commit.

Note that amending a commit modifies the commit history, so you should avoid amending commits that have already been pushed to a shared repository. If others have already based their work on your previous commit, it may cause synchronization issues and conflicts.

It's important to use the "git commit --amend" command with caution, especially if you have already pushed the previous commit to a remote repository.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool