2

Here's what happened, I accidentally reverted the develop branch in our Git repo and it reverted back to last week erasing one week's code and data.

This is the command I used to revert

git reset --hard <revision_id_of_last_known_good_commit>
git push --force

Unfortunately, I wasn't in my branch when I ran this command and it wiped data and set the HEAD to what it was 7 days ago.

Git branches:

  • develop
  • resetfeature (my remote branch)

Instead of reverting the remote branch, I reverted the "develop" branch.
How can I recover the data I lost?

koninos
  • 4,969
  • 5
  • 28
  • 47
Asb
  • 49
  • 4

2 Answers2

2

Read the full answer provided here:

How to move HEAD back to a previous location? (Detached head)


The best way is to use the git reflog to recover your changes

git reflog

git reflog will display any change which updated the HEAD and checking out the desired reflog entry will set the HEAD back to this commit.

Every time the HEAD is modified there will be a new entry in the reflog

git reflog
git checkout HEAD@{...}

This will get you back to your desired commit

enter image description here

So checkout your local reflog to find out the desired commit you wish to revert to and then checkout out and branch (again read the attached full answer how to do it)

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
0

I recovered my data using this tutorial,

http://effectif.com/git/recovering-lost-git-commits

Thanks everyone for the answers.

Asb
  • 49
  • 4