Warning: I'm a newbie and you may want to wait for one of the true experts
to chime in. But, in the past, I've had good luck with a very simple
git reset --hard HEAD^
to revert everything back to the previous commit. If you haven't done a
commit since "messing up", you might as well just:
git reset --hard HEAD
If you're really scared, before doing the above, you might want to copy the
working tree "elsewhere" You don't say what OS you're running. I'm a Linux
user and don't use Windows much at all. In Linux, you can simply:
cd "git working directory" #(replace with the real directory you were in)
rsync -av . ~/backup-$PWD
BTW - the beauty of git is that the only way to lose a file for good is to
never commit it. You can always get back a file which has ever been
committed unless you do some really terrible things to destroy the git
maintained archive file.
Another possible way to get back files, if you don't want to do a reset
would be something like:
git cat-file HEAD:file-name.ext
which will display the file contents on the terminal. If you want to save
the data, just redirect into a file:
git cat-file HEAD:file-name.ext >file-name.ext
Again, you can see "file-name.ext" at various commit points by replacing
HEAD with HEAD^ or HEAD~2 and so on.
On Friday, December 28, 2012 10:09:38 AM UTC-6, Trans wrote:
> Hi, I just screwed my repo and need advice on how to get it back.
> I have been doing some major work on a project, and was finally ready to
> push it. Foolish me did the work in master. So I go to push and I am told,
> "To prevent you from loosing history non-fast-forward updates were
> rejected...". Yatta yatta. I don't see why I got this message at all. I am
> the only person who has worked on the project and this is the only repo
> that has ever pushed upstream. So I figure whatever it is, it much be some
> miniscule change, nothing to fuss over. And as the instructions say, "Merge
> the remote changes (e.g. 'git pull'), before pushing again", I did so.
> I got six huge CONFLICTS and 5 files were DELETED! :-( I can fix the
> conflicts, but how do I get the deleted files back? I tried to checkout the
> last commit reference but it won't let me do so until all the conflicts are
> At this point I am scared to breath hard on my keyboard. I don't want to
> do anything until I get some expert guidance for risk of loosing the files
> for good.