GIT: Update commit's comment after push

Why I needed to do it



Lately I’ve dealt with an issue  on my project cordova broadcaster plugin


I’ve fixed it, committed and published to NPM  the new release of plugin.


I was happy for contribution and also because I had quickly answered to the request, but, after a while,  I received following comment on such issue:


Changes look good.
Fyi to reference an issue in a commit message you should use the syntax fixes #10 instead, so that the commit will actually be referenced in the issue feed.


So … I forgotten to comment, in the right way, the related commit and I have already pushed all … damn! :-(


Then I’ve started to search for a solution and “googling” I got a lot of results related to fix last commit using amendment ( — amend).


After a bit, finally, I found it on SuperUser and, once applied, the commit’s comment is, magically updated in the right way.


… Just one word: “Awesome”.


So .. I would share with you the procedure just in case you have to deal with this situation.  Such procedure is also known as rebase commits against a point in time

Rebase commits against a point in time



Checkout the master branch and perform a git rebase as shown below


$ git rebase -i <commit hash you want to change>^


This start a process for rebasing commits against a point in time and will open your default editor (usually vi) with a list of commits and actions (see here ) for each one. By default, the action is pick that means: include such commit .


For any commit you wish to change the message, change from pick to reword. After that, save and close editor (in vi  :wq).


For each commit, you'll get an editor to edit the commit message. Change it as you see fit, save and close editor  (in vi  :wq).


Once you're done editing all the commit messages, you'll return to the command prompt, and have a new tree with the updated messages.


You can now upload them to github by using:

git push origin --force.


Et voilà … you got expected result


Conclusion



However git never ends to amaze me, I didn’t know such feature related to rebasing process but I think that there are a lot of git’s gems that I ignore.


I can’t image to work without git anymore


Happy Coding

Comments

  1. Thanks for sharing this informative content , Great work
    Leanpitch provides online training in Advanced Scrum Master during this lockdown period everyone can use it wisely.
    Advanced Scrum Master Training Online

    ReplyDelete

Post a Comment

Popular posts from this blog

Google Web Toolkit Vs AngularJS

PlantText: The new "Online" UML Editor powered by PlantUML

PlantUML & Maven - Enrich your project's documentation