-1

After second commit {5}, I have made good amount of changes but didn't add them. And then use git reset --hard HEAD^ and lost all those changes. Is there any way to get them back?

git reflog

8980738 (HEAD -> master) HEAD@{0}: checkout: moving from 70ef608a62f3947d5042da33b857a69ea10b719e to master

70ef608 HEAD@{1}: checkout: moving from master to 70ef60

8980738 (HEAD -> master) HEAD@{2}: commit: Configure react router

bdc9be3 HEAD@{3}: reset: moving to HEAD

bdc9be3 HEAD@{4}: reset: moving to HEAD^

70ef608 HEAD@{5}: commit: Add Navbar inside a component

bdc9be3 HEAD@{6}: commit (initial): Add basic nav-bar

  • 1
    *Uncommitted* changes are lost though: [recover-from-losing-uncommitted-changes-by-git-reset-hard](https://stackoverflow.com/questions/5788037/recover-from-losing-uncommitted-changes-by-git-reset-hard) I could be wrong but that's what I take from that answer. It seems people love to answer questions about uncommitted changes but explaining how to recover committed changes - so you have to read carefully. – topsail Aug 04 '22 at 21:04
  • 1
    https://stackoverflow.com/search?q=[git]+undo+hard+reset – phd Aug 04 '22 at 21:10

1 Answers1

1

If by didn't add them you mean that you did not commit them (as the git reflog also shows), --hard will discard all uncommitted changes (since these are not tracked by git). If this is the case, I'm afraid there is no way to recover your untracked changes
Here's a more detailed answer here: https://stackoverflow.com/a/27990599/16815462

Vlad Nitu
  • 147
  • 1
  • 11