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

1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay