gitduplicates

git tree contains duplicate file entries


I struggled with some line-ending problems about 20 commits back and some weird things happened. Now git fsck shows:

Checking object directories 100% (256/256), done.
error in tree ee2060e71cb36d33be5ddc1fe9ca8d7dd0ab35cd: contains duplicate file entries
Checking objects: 100% (8633/8633), done.

and git show ee2060 shows:

File1.cs
File2.cs
File2.cs
File2.cs
File3.cs

This is preventing me from pushing to my remote. git push shows:

error: unpack failed: index-pack abnormal exit
To https://github.com/username/Project.git
 ! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'https://github.com/username/Project.git'

I have tried repacking and garbage collecting. How can I resolve this problem?


Solution

  • I finally fixed the repo by doing the following

    1. do a fresh clone from github, which only included commits before the problem occurred
    2. add my messed up repo from the filesystem as a remote on the new clone
    3. painstakingly check out commits from the bad repo into the working copy of the new clone

      git checkout fe3254FIRSTCOMMITAFTERORIGIN/MASTER/HEAD . // note the dot at the end
      // without the dot, you move your head to the commit instead of the commit
      // to the working copy, and seems to bring the corrupt object into your good clone
      
    4. commit each in turn, manually copying the commit message from the other repo
    5. remove the corrupt repo from remotes
    6. garbage collect + prune

      git gc --aggressive --prune=now
      
    7. weep happily as git fsck shows no duplicate file entries