如何跳过 lfs 预接收挂钩或将 lfs 对象一起删除
How to skip lfs pre-receive hook or drop the lfs object all together
我有一个应该迁移到 Github 的 BitBucket 存储库。它对大文件使用 git lfs 并且有一些损坏的 lfs 对象,这阻碍了推送到 github(现在是下面命令中的 origin
)。推送总是 returns 错误 Your push referenced at least X unknown Git LFS objects
.
我现在想知道我是否可以忽略预接收挂钩或 drop/delete 有问题的 lfs 对象一起忽略。我不太关心这些文件,因为它们已经很旧了,现在甚至不在回购协议中了。
# 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'
我尝试使用 git lfs migrate export
但没有成功。它也只是抱怨服务器上不存在 lfs 对象。
此外,我以前曾尝试使用BFG repo cleaner覆盖历史记录,但没有成功。也许,我需要重试,因为这听起来像是一种合理的方法。但现在已经是几周前了,我不记得到底是什么失败了。
有人知道实现此目的的简单方法吗?同样,我不关心丢失那几个 lfs 对象,但我更关心保持 git 历史记录。
我确实用 BFG repo cleaner 重试了这个方法,现在效果很好。另外,我确实直接推送到新的仓库(Github),这样做的好处是更新根本不会触及原始仓库。
因此,通过以下措施,我可以将存储库从 Bitbucket 迁移到 Github,同时从存储库中删除损坏的文件。
# 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
我有一个应该迁移到 Github 的 BitBucket 存储库。它对大文件使用 git lfs 并且有一些损坏的 lfs 对象,这阻碍了推送到 github(现在是下面命令中的 origin
)。推送总是 returns 错误 Your push referenced at least X unknown Git LFS objects
.
我现在想知道我是否可以忽略预接收挂钩或 drop/delete 有问题的 lfs 对象一起忽略。我不太关心这些文件,因为它们已经很旧了,现在甚至不在回购协议中了。
# 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'
我尝试使用 git lfs migrate export
但没有成功。它也只是抱怨服务器上不存在 lfs 对象。
此外,我以前曾尝试使用BFG repo cleaner覆盖历史记录,但没有成功。也许,我需要重试,因为这听起来像是一种合理的方法。但现在已经是几周前了,我不记得到底是什么失败了。
有人知道实现此目的的简单方法吗?同样,我不关心丢失那几个 lfs 对象,但我更关心保持 git 历史记录。
我确实用 BFG repo cleaner 重试了这个方法,现在效果很好。另外,我确实直接推送到新的仓库(Github),这样做的好处是更新根本不会触及原始仓库。
因此,通过以下措施,我可以将存储库从 Bitbucket 迁移到 Github,同时从存储库中删除损坏的文件。
# 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