Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git tree contains duplicate file entries

Tags:

git

duplicates

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?

like image 881
Christopher Best Avatar asked Jun 07 '12 12:06

Christopher Best


2 Answers

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
like image 76
Christopher Best Avatar answered Nov 16 '22 04:11

Christopher Best


I had a problem of this ilk and all the solutions here and in other SO threads failed to fix it for me. In the end I used BFG repo cleaner to destroy all the commits which references the bad folder name, which was probably overkill but successfully repaired the repo.

like image 28
Henry Wilson Avatar answered Nov 16 '22 03:11

Henry Wilson