Git roll back – reverse and change Git commit message

Today I had a problem (because I believe any learning starts with a problem) after being asked to undo some changes I had already pushed to a repository in a Jira ticket-branch.  I admit it is not the kind of thing I normally do, but I needed to rewind some of the changes I had made and thought Sourcetree could help me with this. The issue is that Sourcetree offers a few different options and I had no idea what to use.

Finally, I went for the Reverse Commit option

Click in the commit you want to discard/roll back and reverse it. This created a new commit with the changes applied to the previous commit undone.

The problem here was that I simply pushed that without reading the commit message and my company has a very strict rule when it comes to it.

So, some more research and I found this thread on Stackoverflow

But how do you change a commit in the Vi editor? Here’s how.

The repository and branch parameters didn’t work but because I was working in a specific branch, I did the push –force-with-lease and it seems to have worked fine. Changes undone with a click of the mouse and learned how to amend the commit message.