프로젝트를 진행하다보니 gitlab에 있는 레포지토리를 깃허브로 미러링해서 가져올일이 있었다
프로젝트중에 용량이 큰 파일들이 포함된 레포지토리는 미러링으로 가져오는데 문제가 생길수가 있다
git push -mirror를 하고 벌어진 결과는 다음과 같았다 ..
오브젝트 나열하는 중: 10559, 완료.
오브젝트 개수 세는 중: 100% (10559/10559), 완료.
Delta compression using up to 12 threads
오브젝트 압축하는 중: 100% (4545/4545), 완료.
오브젝트 쓰는 중: 100% (10559/10559), 742.50 MiB | 97.44 MiB/s, 완료.
Total 10559 (delta 4684), reused 10559 (delta 4684), pack-reused 0
remote: Resolving deltas: 100% (4684/4684), done.
remote: error: Trace: c88ff170f89e64331b7f34e7e50ee865018ea10f0f11499e358968763563b38c
remote: error: See https://gh.io/lfs for more information.
remote: error: File app-release.apk is 152.56 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File exec/dump.zip is 119.70 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File exec.zip is 119.90 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File exec/dump/mine_hexagon.sql is 472.87 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage
! [remote rejected] refs/for/dev-BE -> refs/for/dev-BE (pre-receive hook declined)
! [remote rejected] refs/for/feat/cors -> refs/for/feat/cors (pre-receive hook declined)
! [remote rejected] develop -> develop (pre-receive hook declined)
! [remote rejected] hotfix_02/MainPageDate -> hotfix_02/MainPageDate (pre-receive hook declined)
....
해결한 방법을 간략히 정리해보겠다
1. 빈 폴더를 만들고 이곳에서 미러링으로 클론해온다
나는 깃랩에서 가져올것이므로 깃랩상의 주소를 적어주었다
git clone --mirror {가져올 레포지토리 주소.git}
2. 클론한 저장소로 이동
cd {레포지토리명.git}
3. lfs를 설치한다
git lfs install
4.
https://rtyley.github.io/bfg-repo-cleaner/
BFG Repo-Cleaner by rtyley
$ bfg --strip-blobs-bigger-than 100M --replace-text banned.txt repo.git an alternative to git-filter-branch The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history: Removing Crazy Big Files Re
rtyley.github.io
여기서 bfg repo-cleaner를 다운받는다
그리고 레포지토리와 같은 위치에 다운받은 jar파일을 가져와준다
5. 아까 git push --mirror를 했을때 에러 로그를 보면 총 네개의 파일에서 용량 문제가 있음을 알수 있었다
나는 다음과 같은 파일들에서 문제가 있었다
File app-release.apk
File exec/dump.zip
File exec.zip
File exec/dump/mine_hexagon.sql
다음과 같이 문제가 되는 확장자들에 대해 git lfs로 관리되도록 히스토리를 재작성하는 과정이 필요하다
나는 처음에 *.확장자명으로 안하고 파일명을 구체적으로 적었었는데, 추후 tracking 및 정리가 잘 안되던 문제가 있었어서
그냥 나도 확장자명을 적어주었다
이 과정은 시간이 좀 걸릴수 있다
되고나면 정리되어야할 부분들에 대해 ~was rewritten이라는 문구들이 보일것이다
git filter-branch --tree-filter 'git lfs track "*.{확장자명}"' -- --all
git filter-branch --tree-filter 'git lfs track "*.apk"' -- --all
이런식으로
6. tracking시킨 확장자들을 각각 다음과 같이 bfs를 통해 정리해주도록 한다
java -jar {bfg jar파일 저장경로} --convert-to-git-lfs '*.확장자명'
7. 다 됐으면 이제 push --mirror로 다시 옮겨준다 (미리 빈 깃허브 레포를 파놓자)
git push --mirror {깃허브 레포지토리 주소}
블로그별로 명령어가 조금씩 달라서 초반에 헤맸던것같다
이렇게 하면 한번에 성공할것입니다 (아마도..)