Posted on August 4 - 2020 in

How to undo your last GIT commit and preserve your changes

Recently I got into a pickle with GIT. I pushed to my development branch which is protected. I had forgotten to check out a branch off of devevelopment in order to be able to push to the repo later for merging.

The problem however was that all my changes had now been moved into a commit that was somewhere in the GIT ether. I needed them back so I could move them to another branch and do a push normally.

Luckily the solution was very simple – the below worked for me perfectly. If you want to undo a commit but preserve the changes you have made use the following bit of code in your terminal:

$ git reset --soft HEAD~1

Start your project

If you feel I can help you with web design project I'd love to hear from you. Getting started is as easy as dropping me an email to start the discussion.

Start Project