How to change a commit description in Git

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


This guide covers the steps and best practices for changing commit descriptions in Git to maintain clear and accurate project histories.

A commit description is a brief explanation attached to each commit that describes the changes introduced.

Changing a commit message should be done with caution, especially for commits that have already been shared with others or pushed to a public repository. It's appropriate to modify a commit description if:

  • The message contains incorrect, incomplete, or misleading information.
  • The commit has not yet been pushed to a public branch or shared with other collaborators.

If you need to change the description of the most recent commit that has not been pushed yet, you can use the git commit --amend command:

  1. Open your terminal and navigate to your repository directory.

  2. Run the following command to modify the last commit:

    Terminal
    git commit --amend

    This command will open your configured text editor (such as Vim, Nano, or Notepad++) with the most recent commit message loaded for editing.

  3. Edit the commit message, save the file, and close the editor. The commit description will be updated for your last commit.

To change the description of an older commit, you must perform an interactive rebase. Be aware that this method rewrites commit history, which can cause issues for other collaborators if not handled carefully.

  1. Identify the commit hash of the commit you want to change by viewing the history:

    Terminal
    git log
  2. Start an interactive rebase to the parent commit of the commit you need to change:

    Terminal
    git rebase -i <commit_hash>^

    Replace <commit_hash> with the hash of the commit you want to change.

  3. Change pick to reword for the commit you wish to change the description of.

  4. Save and close the editor. Git will start the rebase process and stop to allow you to change the commit message of the commit you specified.

  5. Edit the message, save the file, and close the editor.

  6. Complete the rebase by following any on-screen instructions to resolve conflicts or continue the rebase.

After amending your commit locally, you need to push the changes to Git. If the commit has already been pushed, you will need to force push. However, be cautious as this can disrupt the history for others who have cloned the repository.

Terminal
git push --force

For further reading see the official Git documentation.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2