How to undo a commit in git?

I have been using Git for a while, and it has become very uncomfortable when I don't have it in my workflow.(If you're a software developer and the company where you work does not have a version control system. Run, my friend, run..) It is a powerful tool to have in your workflow and yes, very easy to use. In other words, I am a big fan of Git.

git logo

The biggest mistake I made while using Git was committing files in a wrong branch.

If you have done a git add . and commit them to the wrong branch like I did. To get past this is actually pretty easy.

Running the following command should undo your last commit:

git reset --soft HEAD~1

Note: the files are still added, but not committed. You can then commit them in your correct branch. Easy?

Humeira Diljore

Humeira Diljore

Developer, lives on a little island call Mauritius in the Indian Ocean. These days, can often be found battling monsters & running around Hyrule.

Read More