Git Restore With Reflog

usecase

The aim of this how-to-guide🏁 is to show the restore of data of for example a deleted commit via git reflog.

  • reflog stands for REFERENCE LOGS
  • record when the tips of branches and other references were updated in the LOCAL REPO

1. Instructions

  • Run git reflog
  • Run git checkout -b <recoverBranch> <sha>
  • the name of the <recoverBranch> is IRRELEVANT & CUSTOM
  • the sha is CRUCIAL & FIXED
  • you may have to commit/stash all changes in the working area before creating a detached head
  • e.g. git checkout -b restoreTests 284270a
  • Recover data by placing them somewhere else
  • Return to master by git checkout master
  • Delete the ad-hoc branch by git branch -D <recoverBranch>

2. sources

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store