Garrick Cheung

Sharing what I know and learn about CSS, MooTools, Javascript, PHP and etc.

Undo a commit in git

Posted on | August 15, 2012 | 1 Comment

I’ve been using git for a while now. And I’ve happend upon a pattern: I commit, and then have to undo my commit because I either missed a file or a change that should go with the commit.

So, how do you undo a commit in git..?

But what is git?

If you don’t know what git is..

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Eureka! The solution:

I searched for a solution and happened upon a solution on Stock Overflow.

Undo a commit and redo

$ git commit ...
$ git reset --soft HEAD^ (1)
$ edit (2)
$ git add .... (3)
$ git commit -c ORIG_HEAD (4)

This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before “reset”.

Make corrections to working tree files.

Stage changes for commit.

“reset” copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.

This has been super helpful.


  • Rafael

    There is a shorter way for doing this.

    git commit # the "broken" commit
    git add missing_file
    git commit --amend -m "New commit message" missing_file

    which is according to git docs rough equivalent for your solution.


    Hello and welcome. My name is Garrick. This blog is focused on web development that I learn and know and stuff. Who doesn't like stuff?!

    Subscribe to my feed



taking viagra woman Cheap Viagra
cheap gerneric viagra?