This assuming your are not yet run “git gc” ( garbage collector), so all the dangling commits are still available.
Run the “git reflog” command (reflog starnds for reference log). This will list of series of history commits with short commit messages and SHA1s, including all those dangling commits. The short commit message is very helpful because normally you won’t remember your commit’s SHA1, but you recognise your commit message.
Find the commit SHA1 you want to restore. For example, assume our commit needs to be restored here is [SHA33ddf]
run “git branch [branchName] [SHA33ddf]”, this will create a new branch with the head point to this commit’s SHA1. Your work has magically restored!
The last step would be set up your new branch to tracking with the corresponding remote branch: “git branch -u upstream/branchName branchName”, assuming upstream is your remote origin.