How to break your git repository


I was cleaning up a few things on my drive and moved several folders around. Unbeknownst to me at the time, one flash drive was still vfat when I thought it was ext2/3. For some reason no obvious warning such as "cannot change permissons on file xyz" appeared when moving files. So I assumed everything worked fine and I committed a small change to a file in my main git repository, which was moved, too. That wasn't so smart. As I ran git status too see how things were looking I got a listing of every file in the repo having been modified. Next I noticed that nearly all files had the executable bit set, all in .git as well. Then I noticed it was a vfat partition and moved the directory back to a Linux partition. Then, back on the old drive, the only error message that came back was:

fatal: Not a git repository

The first thing I tried to remedy this was removing the executable bit from all files and a helpful forum post supplied the useful one-liner:

find . -type f -print0 | xargs -0 chmod a-x

Still, the fatal error message persisted. It had to be somehow connected to the .git directory which looked fine but when compared to a newly created test repository it became obvious that the one commit on the vfat partition had changed the filename HEAD to head…must be a default policy for case-insensitive filesystems… Anyway, all worked well after renaming head back to HEAD and a simple git checkout -f got rid of any remaining problems with incongruent files. Maybe this post will be a helpful shortcut to somebody else who wasn't paying attention.