Freelance Web Designer in Dubai & SEO Expert in Kerala
01 / 01

Change a Git commit message after a push

This article will help you to change the Git change after committing the code in to the repository

Two way you can amend the commit changes

  1. Change in the last commit
  2. Changes in the last 5 commits

1. Change in the last commit

This will help you to change in the last commit changes

 

If you changed the message of most recently pushed commit, you would have to force push it.

Syntax

git commit --amend -m "New message"

git push --force

Example

git commit --amend -m "After finishing the Project Module"

git push --force

Note

  1. Make sure that your fellow developer aware about this changes
  2. Properly use the Repository Name Branch Name

2. Amend in pushed commit last 5 commits

This will help you to make the changes in the last committed

git rebase -i HEAD~3 

pick a5bf3ae After Adding Buttom
pick f79eb62 Using State Hooks
pick 4788f64 After Changing Button Color

# Rebase 172e023..4788f64 onto 172e023 (3 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
  1. It will prompt the last commits in the console
  2. You are going to edit this by using VIM Editor
  3. You can press the I button to insert or Edit the change
  4. You can change the pick to reword to make the change in commit
  5. Now you may press Escape and :wq to save and quite VIM editor

Now you can proceed to push the changes

git push –force

Note

  1. Make sure that your fellow developer aware about this changes
  2. Properly use the Repository Name Branch Name
by anvar
Published : Mar , 22

Post a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WhatsApp Logo Chat
design specialist