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