0

TL;DR: I deleted the .git directory, recreated it with git init, then did a git commit, then did a git push using --force option and overwritten the remote repository with an empty one.

So as a total newbie I was trying to use rclone to backup my stuff to gdrive but it messed up my work projects .git folder for some reason (probably my fault.

fatal: not a git repository (or any parent up to mount point /) 
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

I tried but couldn't fix that. so instead as an idiot I though I would delete .git folder and pull it again from repo.

When I re cloned repo (all data was safe) I got .git folder and everything was working until I pushed new commit and when I checked on git-hub I couldn't see any previous ones. that last commit lost all of my previous commits, and branches.

All my code is safe but I lost previous commits, is there a way to get those back?

Those are very important as I'm working for a company and not on personal project.

git version 2.35.1

I deleted the .git folder using

rm -rf .git

also I have files saved both local and on git-hub repository. I want the .git folder restored.

did I screw up at a point where nothing can be done ? is there a way to get all my previous commits info and if so how can that be done ?

Thanks in advance for any useful answers

  • Do you have history in your local repo? What does git reflog say? – antlersoft Feb 15 '22 at 02:04
  • it's only shows the last commit (which I believe overwrite my commit history on git) – newbie pete Feb 15 '22 at 02:07
  • So you deleted the .git directory, recreate it with `git init`, `git commit`, then you did a `git push` to the server. Did you need to use the `--force` option? Sounds like you might have overwritten the the remote repository with your empty one. – Matt Clark Feb 15 '22 at 02:48
  • Totally correct sir, that is exactly what happened, do you have any solution in mind that can save me? – newbie pete Feb 15 '22 at 02:55
  • 1
    "I deliberately trashed my local repo and then I deliberately copied the trashed repo to the remote, trashing _that_ repo as well." So unless you have some third copy of this repo (eg ordinary copy or backup or in the trash), that's that. You've succeeded in destroying your whole history. – matt Feb 15 '22 at 03:54
  • my coworker cloned my repo couple days ago, do you think his ".git" directory would have all the commit history ? Anyway I think I should try that, thanks for the info. – newbie pete Feb 15 '22 at 04:57
  • 1
    Copying/cloning your coworker’s copy will get you most/all of the way. If the remote has not yet `git gc`ed (not in your control) all the commits still exist on the remote and can be recovered, all you need is to find the commit hash - it would have been in the cli output when force pushing, for example. – AD7six Feb 15 '22 at 07:51
  • thanks, that page gave me lot of insight but still it didn't help fixing my problem sir. git fsck --lost-found only shows one of the commits which I made in the beginning of creating repo and blobs. – newbie pete Feb 15 '22 at 15:41
  • 1
    thanks for the reply, I had to contact github support to get the hash of last good commit which I didn't find anywhere else and after that it was easy to create another good branch. then do pull request from that branch to main. Thanks for helping out. – newbie pete Feb 16 '22 at 21:45

0 Answers0