Git Restore With Reflog

Pavol Kutaj
Mar 25, 2021

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

--

--

Pavol Kutaj

Today I Learnt | Infrastructure Support Engineer at snowplow.io with a passion for cloud infrastructure/terraform/python/docs. More at https://pavol.kutaj.com