Undo latest commit
Sometimes you want to undo the latest commit....
git reset HEAD~1 --hard
or...
git reset HEAD~1
if you want to keep the code changes (they will end up in the working dir).
Sometimes I use git reset HEAD~1
then git add -p
to y/n hunks I agree/disagree with (like a code review). Then at the end a git diff
to see the code I do not agree with.
Then to reset the branch I'd either git reset HEAD@{1} --hard
or git reset origin/<branch-name> --hard
(whatever points to the commit I was on).
Written by Kristian Lewis Jones
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
Related Tags
#git
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#