从提交历史记录中删除大于 100MB 的文件 - 迁移到 Github 失败

Kis*_*ore 6 git github git-commit git-lfs

我正在尝试将一个项目从 GitLab 迁移到 GitHub。.dat,.csv,.exe,.pkl存储库大小为 685.83MB,由几个超过 100MB 到 3383.40 MB 的文件组成。它因以下错误而失败。

GitLab To GitHub Migration Steps:-
$ git clone --mirror git@your-gitlab-site.com:test/my-repo.git
$ cd my-repo.git
$ git remote set-url --push origin git@github.com:test/my-repo.git
$ git push

Error
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: File Src/project/label/file1.dat is 476.32 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
remote: error: File Src/models/label/file2.dat is 2431.49 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
remote: error: File test/test1/label/model/file3.exe is 1031.94 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
remote: error: File test/test2/usecase/filemarker/file3.csv is 997.02 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
remote: error: File src/msg/sports/model.pkl is 3383.40 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
remote: error: File test/movie/maker/marker.dat is 1373.45 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
remote: error: File project/make/level/project/realmaker.csv is 1594.83 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB
remote: error: File src/moderm/network/test.pkl is 111.07 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB

Git LFS/BFG  Method:
$ git clone --mirror gitlab-heavy-repo 
$ cd gitlab-heavy-repo.git 
$ java -jar bfg-1.12.5.jar --convert-to-git-lfs '*.dat' --no-blob-protection
$ java -jar bfg-1.12.5.jar --convert-to-git-lfs '*.exe' --no-blob-protection
$ java -jar bfg-1.12.5.jar --convert-to-git-lfs '*.csv' --no-blob-protection
$ java -jar bfg-1.12.5.jar --convert-to-git-lfs '*.pkl' --no-blob-protection
$ git reflog expire --expire=now --all && git gc --prune=now
$ git lfs install
$ git remote set-url origin git@github.com:some-org/githubheavy-repo.git
$ git push 
Run Code Online (Sandbox Code Playgroud)

即使经过上述过程,它也会失败并出现相同的错误。看来 Git LFS 有 2GB 的限制。因此尝试从存储库中完全删除上述较大的文件。按照下面的方法删除。

1) git clone gitlab-heavy-repo
2) cd gitlab-heavy-repo
3) git filter-branch --force --index-filter "git rm --cached --ignore-unmatch Src/project/label/file1.dat" --prune-empty --tag-name-filter cat -- --all
4) git reflog expire --expire=now --all
5) git gc --prune=now
6) git push origin --force --all
7) git push origin --force --tags
8) rm -rf .git/refs/original/
Run Code Online (Sandbox Code Playgroud)

对上述所有较大的文件重复相同的步骤。但现在在 Gitlab 存储库中显示存储大小 -1.9-GB最初它只是685.83MB.

请纠正我。提前致谢。

Qum*_*ber 6

将所有超过 100MiB 的文件添加到 .gitignore

find . -size +100M | cat >> .gitignore
Run Code Online (Sandbox Code Playgroud)

如果您尚未提交文件:

从 .gitignore 读取文件并将它们从存储库中删除(而不从磁盘中删除它们):

On Linux:

git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
Run Code Online (Sandbox Code Playgroud)

On macOS:

alias apply-gitignore="git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached"
Run Code Online (Sandbox Code Playgroud)

On Windows:

for /F "tokens=*" %a in ('git ls-files -ci --exclude-standard') do @git rm --cached "%a"
Run Code Online (Sandbox Code Playgroud)

如果您已提交文件:

您需要从提交历史记录中清除它们。运行以下命令从所有以前的提交中删除文件:

警告!重写历史是危险的。

On Linux and macOS:

git filter-branch --prune-empty -d ~/tmp/scratch \
  --index-filter "git rm --cached -f --ignore-unmatch PATH/TO/FILE" \
  --tag-name-filter cat -- --all
Run Code Online (Sandbox Code Playgroud)

On Windows:

git filter-branch --prune-empty -d /tmp/scratch \
  --index-filter "git rm --cached -f --ignore-unmatch PATH/TO/FILE" \
  --tag-name-filter cat -- --all
Run Code Online (Sandbox Code Playgroud)

(将 PATH/TO/FILE 替换为实际文件的路径) Greg 在 此处
的回答中更好地解释了此命令


如果您需要对文件夹而不是文件运行上面的命令,请在第二行-r后面添加一个开关:git rm

... \
  --index-filter "git rm -r --cached -f --ignore-unmatch PATH/TO/FOLDER" \
  ...
Run Code Online (Sandbox Code Playgroud)

git rm可以采用多个参数,因此您可以在第二行中添加多个路径:

... \
  --index-filter "git rm -r --cached -f --ignore-unmatch FILE1 FILE2 FOLDER1 FOLDER2" \
  ...
Run Code Online (Sandbox Code Playgroud)