Prabir's Blog

open source geek and lover of all tech  

Sep

Undo in Git

We are not perfect. There are may times when we make a mistake and need to revert back to the previous stage. Usually the most common way to do it would be by using Ctrl+Z.

How many times have you wanted to undo your commit? Did you ever make a spelling mistake? You did the wrong commit. If so here is the answer.

There are basically two ways to do it in Git. One is using soft reset and the other one using hard reset.

1. Soft Reset

This undo's your commit and keeps changes you have made in the working tree.

git reset --soft HEAD^

2. Hard Reset

This undo’s your commit and also resets your working tree to the last commit.

git reset --hard HEAD^

Lately I have been a fan of git for making it as my default version control system. I have been learning it and also trying use it for my current projects.

There are quite a bunch of free git hosting around, but you basically have to open source your codes. So I searched around the net for some private hosting, which allows to hide the codes from public access. It might be helpful for you guys.

Here’s the list.