2

Using Win7, 64-bit.

I use the GitExtensions GUI, which has been working fine for 3 months. Today I did a commit, immediately pushed to my server repo, and shut down. When I powered back up later in the day and tried to do another (local) commit, GitExtensions told me that I have NEVER committed to that repo and showed 119 files with changes.

Obviously something got fried, so my first thought was to do a pull from my server repo. Guess what? The server repo is also showing that I have NEVER committed to it.

So then my next thought was GitExtensions is lying to me. So I moved over to Tortoise GIT and did a "View Log". Guess what? GitExtensions isn't lying. Tortoise GIT also shows that I have NEVER committed to my repo.

When I physically browse in the repo, I can see all the object files with reasonable-looking timestamps covering the 3 months I've been working on this project.

How can I get GIT to recover and realize that I have 3 months of commits STILL IN THERE? The only articles I've seen are on how to recover individual lost commits that need to make use of an earlier commit as a starting point. Obviously that's not going to help me since I can't see ANY commits.

Thanks for your help.

xpnctoc
  • 63
  • 8

3 Answers3

1

First, back up your repository so that any attempted fixes that fail don't corrupt it worse.

git fsck can help find and fix errors in the repository.

git reflog can help you identify orphaned commits and reconstruct the history.

This answer on the "bad default revision" error may help.

If fsck does nothing for you, my first thought would be to try to reset the remote repository's HEAD back one commit and then try a re-clone.

Community
  • 1
  • 1
wadesworld
  • 13,535
  • 14
  • 60
  • 93
  • FYI when the error described happens `git reflog` actually fails saying there are "no commits" - so it's actually no use – PandaWood Jul 22 '21 at 02:33
1

Check what you get for "git log master" or any other branch. If that works, you can use "git bundle" to explicitly export commits and all related objects. Rinse and repeat for ask other branches in .git/refs.

It would probably be best to drop down to the command line to get this fixed. Download the latest msysgit.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
0

Is the .git folder still in there? If it is that is where git stores all it's information. If not, then there is nothing to get back. If not, then your local git is gone. If you .git is still there, try running git log and see what it shows.

If your .git folder is gone, then you should be able to do a "new" clone from your server to retrieve everything.

Ryan Gibbons
  • 3,511
  • 31
  • 32
  • Yes, the .git folder is there and I can see all the objects still in there. Did a "git log" and got this message: "fatal: bad default revision 'HEAD'." – xpnctoc Jan 03 '12 at 00:56
  • And I can't clone from the server. The remote repo is exhibiting the same behavior. It's like the GUI tools I use corrupted the commit and then, because I immediately pushed to the server, that corruption got transferred to the server repo as well. – xpnctoc Jan 03 '12 at 00:58
  • So your GUI tool performed a forced push without asking your?! – ThiefMaster Jan 03 '12 at 01:24
  • No, there's an option in the GUI to perform a push immediately after the commit. I usually enable that option so that my latest work is immediately stored on two different machines. I guess the lesson learned is to keep the server repo behind the local by at least one power cycling of my development machine. – xpnctoc Jan 03 '12 at 01:46