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?
Asked
Active
Viewed 662 times
0
-
1I think this is what you're looking for: https://stackoverflow.com/questions/3973994/how-can-i-recover-from-an-erronous-git-push-f-origin-master https://stackoverflow.com/questions/14476236/is-there-anyway-to-undo-git-push-f – Andr Fabin Castellanos Aldama Jul 07 '20 at 01:09
-
Could you please share the commands that you used? – Marcos Jul 07 '20 at 01:12
-
I just used: git push -f "url of repo" master – Meh Jul 07 '20 at 01:42
1 Answers
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 ongit reflog origin/master
(orgit reflog origin/anybranch
) : the history of all the places you have seen fororigin/master
, updated each time you rangit fetch
orgit 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