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

varadan13

Aneesh

Posted on June 23, 2023

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.

💖 💪 🙅 🚩
varadan13
Aneesh

Posted on June 23, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related