[alias]
r = !sh -c \"git log -1 --format=oneline\" && git reset
Using git r instead of git reset now prints the current HEAD before resetting.
$ git r --hard HEAD~23
9d09ffc3ba1a65fc7feefd21abd5adacf3274628 dix: NewCurrentScreen must work on pointers where possible
HEAD is now at 5083b56 Revert "mi: move switching screen on dequeue to separate helper function"
Whoops. Fat-fingered. A git r --hard 9d09ffc3ba1a65fc7feefd21abd5adacf3274628 will undo the above and get you back to your previous HEAD.
Note: git fsck --lost-found will also help you to find the commit again, but it'll take more time and effort.
Update: as mjg59 pointed out to me, git reflog records git resets, thus making it easy to find the previous HEAD too. Wish I'd known that command sooner ;)
2 comments:
I like the other part of reflog story:
git reset HEAD@{1} will undo the wrong git reset, commit, etc things.
git log -g
is also useful to navigate the reflog.
Post a Comment