I know that undoing a single git reset or git reset --hard command has been asked and answered, but I have really messed things up and am not sure how to proceed because I need to undo several mistakes. I was actually following some of the existing answers and seemed to have messed things up even more, and it is very important that I recover these files. Now I'm too nervous and just need some exact help and the exact command to do what I need.
My original issue is that I checked out a branch locally. I thought that my local branch was the out of date one and that the remote branch was the most up to date. (I was working on two separate computers on the same branch at different times.) So I did a git reset and then a git reset --hard because I forgot to include the --hard the first time. However, I really messed up because it was my local branch that had the most up to date code on it, and so I inadvertently wiped out a day's work.
Here are the exact commands that I ran, in sequence:
> git checkout cleanup-client <-- I want to return to the point of time directly after this command
> git reset origin/cleanup-client
> git reset --hard origin/cleanup-client
> git status
> git reflog
> git reset 5011960 <-- I tried reading existing answers and performed this
> <I unstaged and discarded all changes via VS Code Git integration>
> git reflog
> git reset bc6968c <-- Another attempt to recover
> <I unstaged and discarded all changes via VS Code Git integration>
Here is the output of git reflog now:
> git reflog
bc6968c (HEAD -> cleanup-client, origin/cleanup-client) HEAD@{0}: reset: moving to bc6968c
5011960 (origin/BACKUP-cleanup-client) HEAD@{1}: reset: moving to 5011960
bc6968c (HEAD -> cleanup-client, origin/cleanup-client) HEAD@{2}: reset: moving to origin/cleanup-client
bc6968c (HEAD -> cleanup-client, origin/cleanup-client) HEAD@{3}: reset: moving to origin/cleanup-client
5011960 (origin/BACKUP-cleanup-client) HEAD@{4}: checkout: moving from migrate-client-to-poetry to cleanup-client
7b2242a (origin/migrate-client-to-poetry, migrate-client-to-poetry) HEAD@{5}: commit: Renaming existing clients to use `snake_case`
91797f6 HEAD@{6}: commit: Update server README
What I am confused about and hesitant about is which SHA to actually use from git reflog. Are the SHAs listed the SHA for before or after the command to the right was executed?
In other words, is git reset --hard 5011960 the command I now need? (Note: I have not ran this, yet, after all the above commands. I.e., the above commands are where I'm at now.)
5011960looks like the correct commit from your description and matches your commandsgit reset --hard 5011960the command I now need?" Is yes, and you need the--hardpart to get your files back to how they were at the time of that first checkout.