If you ever hit reset and then felt your heart sink because commits vanished, git reflog is the rescue dog you did not know you needed. It tracks HEAD and branch movement so you can find lost commits and put things back where they belong without performing ritual sacrifices.
Reflog records local reference changes. That makes it great for recovery after accidental checkouts resets or branch deletions. The reflog is not a permanent time machine but it will hold recent moves long enough for you to act.
Run this to see recent HEAD and branch moves
git reflog
Scan the output for messages that match the lost work. If you do not have the raw hash the numbered form like HEAD@{3} is handy.
Once you find the right entry create a branch so you do not risk the main branch
git checkout -b recovered-branch HEAD@{3}
This preserves the commit and gives you a sandbox to inspect changes and run tests.
If you are confident and do not mind overwriting working files you can move the target branch pointer
git checkout main
git reset --hard HEAD@{2}
If you prefer less destruction merge or cherry pick from the recovered branch instead. That is the safer and less anxiety inducing option.
Once recovered push the branch to the remote so your work survives local reflog expiry
git push origin recovered-branch
When the changes land in the intended branch delete any temporary branches to keep the repo tidy.
In short do not panic and do not type random resets while hyperventilating. Read the reflog find the commit create a branch and restore safely. If all else fails reboot your machine and try again with coffee and better typing.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.