3

By mistake I have reset hard by using following command :

git reset --hard HEAD~

Now I want to undo all commits and the affect which git reset have made,and want to goto where I started today, Can I do that?

  • Find the last commit of yesterday, and do `git reset --hard ` – Ivar Aug 10 '17 at 14:45
  • Possible duplicate of [Recover from git reset --hard?](https://stackoverflow.com/questions/5788037/recover-from-git-reset-hard) – Steve Aug 10 '17 at 14:46
  • 1
    Perhaps [this answer](https://stackoverflow.com/a/40939503/5358968) might be of particular use with `git-reflog` – Steve Aug 10 '17 at 14:48

1 Answers1

3

git reset does not create commits.

The best bet for undoing a git reset is to do another git reset, using the reflog.

git reflog

should show a list of where HEAD has recently been (in the local repository). Hopefully one of those entries will be "where you started today". In the case where the reset is all you did, this will be identified as HEAD@{1}, so you would then do

git reset --hard HEAD@{1}
Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52