Categories
Uncategorized

Amending Last Commit

Let’s say you made a few code standard fixes and committed them as “Fix code standard issues”. Now you find some more code standard issues and fix those as well.

You now have the option to make another commit with “Fix code standard issues” or you could amend the previous commit to include the newly made changes in the previous commit.

This can be done with git commit --amend command.

The sequence would be:

  1. Made some changes
  2. Staged those changes with git add
  3. Committed those changes with git commit
  4. Made some more changes
  5. Staged those changes
  6. Committed those changes with git commit --amend
  7. Finally pushing those changes with git push repository-name branch-name or force push them (if the previous commit was already pushed) with git push --force repository-name branch-name

This can also be simply used to make changes to the commit title and description. More on this here and here.

Leave a Reply

Your email address will not be published. Required fields are marked *