What could be the reason my git repositories keep getting corrupted/broken?

Hi, I am running a Meteor/React/Apollo stack, and I have 2 private repository containing all these files for 2 different projects using the same stack. I’m running Fedora 34 and git version 2.31.1.

I have an extremely peculiar situation going on and I can’t figure out what’s causing it. These 2 repositories constantly become corrupted/broken.

I’m currently only working on these 2 projects and as such do not have long term experience dealing with any other repositories.

I use my command line, no GUI, and the only git commands I use are:

git add .
git commit -m "some message"
git push

In that same directory, I only ever run two other commands, meteor to start the Meteor/MongoDB server, and robo3t to access a GUI to interact with the Mongo server.

The IDE I use is VS Code. Since I’m working alone, my typical workflow is I push my day’s changes at the end of the day.

I’ve faced a slew of errors with the repositories:

  1. git corrupt loose object (there is a SO link but I can’t link it as I’m limited to 2 links in a post)
  2. fatal could not parse HEAD
  3. error: object file is empty (9/10 times this is the error)

Error #3 occurs the most. The first 2/3 times it happened I diligently followed the StackOverflow answers and fixed the repository. Now I’ve given up on constantly fixing the repository. I move my files out, clone my repository from GitHub, and copy/replace the files back in. This is MUCH faster.

Here’s why it’s extremely weird that these corruptions keep happening:

  1. Nothing else on my computer interacts with git. No other programs, GUIs, only when I interact with git in my terminal.
  2. I do not personally edit any of the git object files, as I have no reason to.
  3. I cannot predict when this happens. As I described above, I pull from my healthy GitHub repository, copy/replace all my new files in, and I can add, commit and push with no issues. The next day, at the end of the day it could become corrupted even though I never interacted with git for the entire day until I’m ready to push.
  4. I have never interrupted a git commit/push by shutting down the machine midway. I always cleanly exit the terminal after the push is successful.
  5. I’ve looked through all my processes running at multiple times of the day and nothing seems out of place as malicious or anything of that sort.
  6. My repository is simple, I only have 1 master branch and I am the only contributor to the repository. As mentioned, it’s a private repository.
  7. It is worth noting that none of my actual files get/are corrupted. Only some git object files.

The only edits I’ve ever done was to change all the authoring history to be under my GitHub account/email as this information wasn’t supplied earlier. And I’ve moved to using SSH for commits instead of HTTPS to avoid authentication every time. These issues persisted both before and after these changes, so they had no noticeable effect.

If anyone is able to give a modicum of advice on how I should go about figuring out what’s causing this, I’d be eternally grateful. It’s a complete pain having to constantly move my files and clone and copy/replace, etc.

I’d primarily check disk and memory, even if you haven’t seen other data break. When the HDD in my laptop broke last year weirdly corrupted data was the first sign that something was wrong, and at first I suspected a Firefox bug, because its history DB broke and I couldn’t edit bookmarks any more, while other things seemed fine.

I’m not familiar with VS Code myself, but I know from discussions on this forum that it has a Git integration. I doubt it’d have such an obvious bug, but it might still be another thing to check.

1 Like

That’s interesting, I’ll check out my hard drive and see if there’s anything up with that. It definitely is pretty old, ~7 years but I’m upgrading soon, so it may be just in time.

I don’t explicitly use the git integration, but VS Code does highlight files which have change yet to be staged, but that’s as far as it goes (I believe). Will need to look into this more as well. Thank you!

1 Like