Wednesday, September 30, 2015

GIT - 'git reset' my explanation

When and how to use git reset.

Case 1:
You have commited changes, but not yet pushed it. (never reset shared (pushed) commits, read this)
AND
You want to undo this commit and continue to work on these changes in it.
git reset --soft HEAD~1

Case 2:
You have commited changes, but not yet pushed it. (never reset shared (pushed) commits, read this)
AND
You want to undo this commit and DO NOT WANT to continue to work on these changes in it.
git reset --hard HEAD~1
In this case all changes of this commit will be lost and you will not see it in your Local Changes list (e.g. in InteleJIdea IDE)

HEAD~1 means 'one commit from HEAD'