How to roll back/undo a GIT commit

GITSo I have done this more times than I care to admit… immediately after doing a commit (but before pushing) I’m like “shoot, I didn’t meant to do that” or “crap, I was supposed to commit that file” or something similar.  And then I find myself searching Google for how to undo a commit because while I do it often, it’s just infrequent enough that I usually forget how I did it last time.  So while I’m hoping this helps someone, I’m actually hoping that by writing a blog post I’ll commit (haha, get it) this to memory.  So first I’ll give credit to Stack Overflow where I found the command I typically use which is:

git reset --soft HEAD~1

This will undo the last commit you made.  And the nice thing is you can also change the “~1” to undo multiple commits if you made multiple mistakes.  And if the above is too hard to remember, I did hear about a simple script you can install called gitjk that is pretty useful and easy to remember.  I haven’t used gitjk myself, but looking through the readme, it looks straightforward.  So hopefully this has helped if you stumbled on this page after doing an accidental commit and you’re trying to figure out what to do.