Changing the commit messages that are already pushed
So in this post, we will be talking about the process of changing the commit messages that are already pushed into the remote. But, before talking about changing those messages we must know about the basics commands of GitHub. For more knowledge of git you can read the following post. Also, it is good to know about the git reset command which is used to reset any changes made by a user in a repo. Use the command
git reset --helpfor more information. Now let’s dive right into the topic. First thing is to check the changes that you have done in the recent past. For that use the following command.
$ git log # This command will show one change in each line # -5 represent the number of messages that you want to read. $ git log --oneline -5
$ git rebase -i HEAD~5
pick 2f8e279 another message pick a04482b One more another message 2 pick 97d5145 no new changes available # Rebase 3bb9b41..a1c796c onto 3bb9b41 (3 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 # ...few other lines
pickis written and in the comments, we can see the description. So, remove the word pick and change it to the word that you want to use for yourself. I removed pick in all the three lines and changes it with
r. I am not using
eas it was not required in my case. So, if anyone out there uses it, share it in the comments. After that, you will be asked to change the commit message one by one in the end. Now say you only want to change a single commit message (last commit message) it is a bad choice to use something like rebase. You can use this command rather.
$ git commit --amend
+sign, otherwise, your changes will be ignored.
$ git push origin +branch_name
$ git push origin branch_name -f
Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!