Migrating large files from an existing repository to LFS does not work
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
This article provides an alternative solution when migrating an existing repository of large files to LFS using the BFG tool does not work.
Environment
Bitbucket Cloud
Diagnosis
You've identified large files in your repository by cloning your repository via --mirror
clone and use the git rev-list
command:
1
2
3
4
5
6
7
8
# git clone --mirror git@bitbucket.org:workspace_id/repo_name.git
# git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| awk '/^blob/ {print substr($0,6)}' \
| sort -r --numeric-sort --key=2 \
| cut --complement --characters=13-40 \
| numfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
Once identified, you've followed the steps mentioned in this documentation on how to use BFG to migrate a repo to Git LFS.
After that, you reached out to us by raising a support ticket to run Git GC (Garbage Collection) against your remote repository. However, the size remains the same.
You cloned your repository via --mirror clone again, but those large files still exist, as if the BFG tool did nothing.
Cause
The BFG Repo-Cleaner is likely leaving large blobs in the repository, which are subsequently handled incorrectly by Bitbucket Cloud.
Solution
An alternative tool such as bozaro/git-lfs-migrate. Using the HTTPS connection is preferable in this case to migrate your large files to LFS smoothly.
Example command usage:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
java -jar git-lfs-migrate.jar \
-s repo_name.git \
-d repo_name-converted.git \
-g https://bb_username:app_password@bitbucket.org/workspace_id/repo_name.git \
"*.cab" \
"*.dll" \
"*.exe" \
"*.gif" \
"*.gz" \
"*.jpg" \
"*.jpeg" \
"*.JPEG" \
"*.lib" \
"*.msp" \
"*.pak" \
"*.tar" \
"*.webm" \
"*.zip"
Was this helpful?