I was writing a README.md file in the remote server and completed that one, but I accidentally did a force push to the remote by using git push origin master
and now the README.md
is gone
Is there a way I can retrieve that commit? I have written a very long README.md file and really want to see if I can get it back :(
I was looking though the git fsck
and couldn't find the one about the README.md that I have commit from the remote server on github.com
Force Pushing Git prevents you from overwriting the central repository's history by refusing push requests when they result in a non-fast-forward merge. So, if the remote history has diverged from your history, you need to pull the remote branch and merge it into your local one, then try pushing again.
The git revert command is used for undoing changes to a repository's commit history. Other 'undo' commands like, git checkout and git reset , move the HEAD and branch ref pointers to a specified commit. Git revert also takes a specified commit, however, git revert does not move ref pointers to this commit.
If it existed in some working copy, go to that repo and use git reflog
to find a revision that contained it and git checkout
to go to that revision (outside of any branch). Then you can copy the file out wherever you want.
If the server is bare it is probably still an object on the server but no kind of git fetch
will copy it to any other repo because there are no references to it. In that case you'll need access to the bare repo to run your git fsck
directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With