0

I made a new file and I wanted to push it to my remote repo. But I accidentally force push the new file and overwrite it. So, I missed my previous files in my remote repo and now only the new added file is available in my remote repo. Is there any way to recover my missed files?

Meh
  • 1
  • 1

1 Answers1

1

git has a big undo stack : git reflog

You can probably find the sha1 of the commit you "overwrote" in one of the following two places :

  • git reflog : the history of all commits that once have been the active commit you were working on
  • git reflog origin/master (or git reflog origin/anybranch) : the history of all the places you have seen for origin/master, updated each time you ran git fetch or git pull

Once you have this sha1, you can :

  • rebase on top of it : git rebase sha1
  • get the previous content of the file and do something with it : git checkout sha1 -- the/file
  • ...
LeGEC
  • 46,477
  • 5
  • 57
  • 104