从提交历史中移除大小超过100MB的文件 - 迁移到Github失败

6

我正在尝试将一个项目从GitLab迁移到GitHub。仓库大小为685.83MB,其中包含一些超过100MB至3383.40 MB的.dat、.csv、.exe、.pkl文件。但是,在迁移时,它遇到了以下错误。

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 

即使在上述过程之后,它仍然以相同的错误失败。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/

对所有以上较大的文件重复相同步骤。但现在Gitlab仓库存储大小为 - 1.9-GB,最初只有685.83MB。

请纠正我。谢谢。

1个回答

5

将所有大于100MiB的文件添加到.gitignore中:

find . -size +100M | cat >> .gitignore

如果您尚未提交文件:

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

在Linux上:
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached

在 macOS 上:
alias apply-gitignore="git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached"

在Windows上:

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

如果您已经提交了文件:

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

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

在Linux和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

在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

(将PATH/TO/FILE替换为实际文件的路径)
Greg在这里回答得更好


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

... \
  --index-filter "git rm -r --cached -f --ignore-unmatch PATH/TO/FOLDER" \
  ...

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

... \
  --index-filter "git rm -r --cached -f --ignore-unmatch FILE1 FILE2 FOLDER1 FOLDER2" \
  ...

1
通过上述命令创建了.gitignore文件,但仍然遇到相同的问题。 - user4948798
路径/到/文件不支持带有空格的文件名。你会如何解决这个问题? - Jesper Hustad
@JesperHustad,请将路径用引号括起来。 - Qumber
@Qumber,该命令已经在引号内了 "git rm --cached -f --ignore-unmatch PATH/TO/FILE",因此将其再次放入引号中是行不通的。 - Jesper Hustad
@JesperHustad 你可以使用双引号和单引号的组合。请参考这个例子 - https://unix.stackexchange.com/a/169511 - Qumber
显示剩余9条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接