Home > Mobile >  How to skip lfs pre-receive hook or drop the lfs object all together
How to skip lfs pre-receive hook or drop the lfs object all together

Time:01-24

I have a BitBucket repository that shall be migrated to Github. It is using git lfs for large files and has a few corrupt lfs objects, which hinders the pushing to github (now the origin in below command). The push always returns the error Your push referenced at least X unknown Git LFS objects.

I'm now wondering if I can either ignore the pre-receive hook or drop/delete the lfs objects in question all together. I don't care much about these files, because they are quite old already and by now not even in the repo anymore.

# git push --no-verify -u origin develop
Enumerating objects: 8299, done.
Counting objects: 100% (8299/8299), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4102/4102), done.
Writing objects: 100% (8299/8299), 127.51 MiB | 2.91 MiB/s, done.
Total 8299 (delta 3864), reused 8279 (delta 3848)
remote: Resolving deltas: 100% (3864/3864), done.
remote: error: GH008: Your push referenced at least 3 unknown Git LFS objects:
remote:     043...a1d2187
remote:     5cd...d01def9
remote:     0e7...9d550ef
remote: Try to push them with 'git lfs push --all'.
To https://github.com/xyz.git
 ! [remote rejected] develop -> develop (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/xyz.git'

I tried to use git lfs migrate export with no luck. It just complained as well that the lfs object does not exist on server.

Also, in the past I tried to overwrite the history using BFG repo cleaner, but I didn't have any success. Perhaps, I need to retry, because it sounds like a reasonable approach. But it's now a few weeks ago already and I don't remember what failed exactly.

Does anyone know of a simple way to achieve this? Again, I don't care of losing those few lfs objects, but I care more about keeping the git history.

CodePudding user response:

I did retry the approach with BFG repo cleaner and it did work nicely now. Also, I did directly push to the new repo (Github), which has the advantage that the original repository is not touched by the update at all.

So following measures allowed me to migrate the repo from Bitbucket to Github while deleting the corrupt files from the repository.

# Clean up repo according to BFG docs.
git clone --mirror git://bitbucket.com/my-repo.git

# Deleting files could also run multiple times
bfg --delete-files {corrupt_file_name}  my-repo.git
cd my-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive

# Set origin to new github repo
git remote rename origin bitbucket
git remote add origin git://github.com/my-repo.git

# Push branches to new origin (github)
git push origin develop:develop
git push origin main:main
  •  Tags:  
  • Related