duplicate file error while pushing --mirror into G

2019-09-03 00:04发布

问题:

I need to push my existing repository to another empty repository in Git. I was getting this following error:

remote: unpack error Invalid tree 300894f515: duplicate entry names
error: unpack failed: error Invalid tree 300894f515: duplicate entry names

After trying several options I was able to rewrite the history and push the master branch finally. But when I am trying to push the --mirror again, it is showing the same error. I am attaching the log here.

  1. git clone URL
  2. git branch -a

    * master
    remotes/origin/HEAD -> origin/master
    remotes/origin/MyTestBranch
    remotes/origin/ABC
    remotes/origin/XYZ
    remotes/origin/TEST
    
  3. git remote add test REMOTE URL

  4. git remote -v

    origin  git@github.................. (fetch)
    origin  git@github................... (push)
    test    https://abc........................................... (fetch)
    test    https://abc........................................... (push)
    
  5. git fsck --full

    error in tree 300894f515b714a42efd603f4196d45c8c1f3c09: contains duplicate file entries
    error in tree a84c6e1cc242cdc4c7d7ce5246be02672d1eaf3a: contains duplicate file entries
    
  6. git filter-branch --index-filter 'mv "$GIT_INDEX_FILE" "$GIT_INDEX_FILE.tmp" && GIT_INDEX_FILE=$GIT_INDEX_FILE.tmp git ls-files -s | git update-index --index-info'

  7. git push test master

    Counting objects: 33396, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (10456/10456), done.
    Writing objects: 100% (33396/33396), 86.61 MiB | 16.05 MiB/s, done.
    Total 33396 (delta 17522), reused 31573 (delta 17001)
    remote: Resolving deltas: 100% (17522/17522)
    remote: Counting objects: 33396, done
    remote: Updating references: 100% (1/1)
    To https://abc.................................................................git
    * [new branch]      master -> master
    
  8. git push --mirror test

    Counting objects: 35959, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (11059/11059), done.
    Writing objects: 100% (35631/35631), 86.91 MiB | 16.52 MiB/s, done.
    Total 35631 (delta 19237), reused 35489 (delta 19127)
    remote: unpack error Invalid tree 300894f515: duplicate entry names
    error: unpack failed: error Invalid tree 300894f515: duplicate entry names
    

How to resolve this issue?

回答1:

I resolved the issue with the steps mentioned below.

  1. At first I did a --mirror clone.
  2. Then executed "git filter-branch -f --index-filter 'git rm -rf --cached --ignore-unmatch SampleApp && git ls-files -s | git update-index --index-info' --prune-empty --tag-name-filter cat -- --all"
  3. Then I did a --mirror push.

Here SampleApp is the file that has been corrupted.



回答2:

Your rewritten history is in refs/heads/master (i.e., the master branch). But filter-branch will have created a backup of the broken history in refs/original/refs/heads/master. Your --mirror push will send that, causing the other side to complain.

You probably want to git update-ref -d refs/original/refs/heads/master.



标签: linux git github