DEV Community

Cover image for Use git commit --amend to add new changes to the previous commit i.e., HEAD~{0}
Aneesh
Aneesh

Posted on

Use git commit --amend to add new changes to the previous commit i.e., HEAD~{0}

Imagine you've just made a commit, feeling confident about the code changes you've implemented. However, upon further inspection, you notice a small adjustment that should have been part of the previous commit. Here's where "git commit --amend" comes to the rescue.

To tackle this situation. First make the required changes in the code and stage it.

Once you've staged the changes, it's time to amend the previous commit. Run the following command:

git commit --amend
Enter fullscreen mode Exit fullscreen mode

This command opens the default text editor (such as Vim or Nano) with a pre-filled commit message. You can modify the message if necessary. Additionally, the staged changes are automatically incorporated into the previous commit.

Close the text editor after editing the commit message. Now, the new changes and the previous changes are merged into one commit.

Top comments (0)