How to modify the last commit message?

Modify the last commit message in the local copy

There are cases when you must alter the last commit message. This can be done by typing the following command in the command line:

git commit --amend -m "My awesome new message" 

Modify the last commit message in the remote repository

First, you must modify the local commit message, as it is described in the previous section. Next, you can push the local state of the branch to the remote repository.

git push --force origin <branch_name>

Demonstration

The video below demonstrates the described commands above:

How to redo the previous git commit?

Redo the previous git commit

In this post, I provide the necessary commands to revise or redo the previous git commit. There are cases when you make an incomplete commit, you miss some files, or you would like to change the content of some files in the last commit. With the following command, you can reset your last commit:

git reset --soft HEAD~1
  • --soft Does not touch the index file or the working tree at all. This leaves all your changed files “Changes to be committed”, as git status would put it. [source: man git-branch]

After that, you can further change the content of the file or stage new files. When you are ready, you can stage the changes and craft a new commit.

Update the changes in the remote repository

If you pushed your commit to the remote repository before the redo, you must force-push the revised commit. This can be done as follows:

git push --force origin <branch_name>

Demonstration

The video below demonstrates the described commands above: