Edit old commit message on github

Sometimes we make mistake in git commit message, especially spelling mistake. Even though I think twice before pressing the enter key after I write the commit message, I made spelling mistake twice or thrice. That’s my bad actually and I accept it.

So let’s start changing old commit message from GitHub. One thing you need to note that this will edit your commit message from the particular branch only.

Step 1: Open terminal or ( cmd for windows user ) and go to the particular repository.

 

Step 2: run command git log

 

Step 3: Choose a commit message which you want to change and count on which position that commit message is. Let’s say it is on 6th position.

 

Step 4: run git rebase -i HEAD~7

by running this message you will get output something like this:

pick 0856faf Message 1
pick 7ef84df Message 2
pick 55930c2 Message 3
pick 9bf24e0 Message 4
pick 412fc71 Message 5
pick 483f8b6 Message 6
pick c101979 Message 7

# Rebase 0c6220f..c101979 onto 0c6220f (7 command(s))
#
# 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

Note: HEAD~7 because we want to edit 6th commit message. For a safe side, we add one more message.

 

Step 5: Change command pick to reword , as we only want to change the commit message. Like as shown below and exit ( ctrl+X )

pick 0856faf Message 1
reword 7ef84df Message 2
pick 55930c2 Message 3
pick 9bf24e0 Message 4
pick 412fc71 Message 5
pick 483f8b6 Message 6
pick c101979 Message 7

( You can edit multiple messages too. )

Note: There are other options that you can do for commits. Those options you can see right below your commit message list.

 

Step 6: After that, you will be asked to change your commit message. So edit it and save it ( ctrl+x ).

 

Step 7: Now run git push --force origin

( use –force is compulsary. Otherwise there will be double commit message )

Note: During push it will show some warnings. Ignore it as it is warning 😉 . Sit back and relax.

 

Yepieeeeeee. Your message is changed

If you have any issue then comment it. I will try my best to solve the issue.

Advertisements

One thought on “Edit old commit message on github

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s