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.