如何从 GitHub 存储库中删除大(> 100MB)文件并成功推送? [英] How to remove big (>100MB) file from a GitHub repository and push successfully?

查看:36
本文介绍了如何从 GitHub 存储库中删除大(> 100MB)文件并成功推送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在无意中添加了一个我不想要的大文件并在无意中添加了大文件后做了其他工作的额外提交(不知道推送会失败)后,我处于与此处描述的相同的情况:

我应该在镜像仓库或原始仓库上运行 BFG?

<小时>

尝试 #1尝试删除文件:

git rm bigfilegit提交大文件推

没有运气.即使后来的提交删除了它,推送仍然停留在尝试上传大文件上:

$ git push

'https://github.com' 的用户名:https://traildreaming@github.com"的密码:计数对象:210,完成.Delta 压缩最多使用 4 个线程.压缩对象:100% (66/66),完成.写入对象:100% (210/210),5.72 MiB |1.47 MiB/s,完成.总计 210(增量 147),重复使用 203(增量 140)远程:错误:GH001:检测到大文件.您可能想尝试 Git 大文件存储 - https://git-lfs.github.com.远程:错误:跟踪:eedddea1fcb95663492e16c14fc3a250远程:错误:有关更多信息,请参阅 http://git.io/iEPt8g.远程:错误:文件 doc/image.eps 为 591.70 MB;这超出了 GitHub 的文件大小限制 100.00 MB到 https://github.com/traildreaming/myrepo.git![远程拒绝] master ->master(预接收钩拒绝)错误:未能将一些引用推送到https://github.com/traildreaming/myrepo.git"

<小时>

尝试 #2尝试了 https://rtyley.github.io/bfg-repo-cleaner/<的说明/a>

但它没有看到阻止我进行推送的大文件:

$ git clone --mirror https://github.com/traildreaming/myrepo.混帐

克隆到裸仓库'myrepo.git'...https://github.com"的用户名:https://traildreaming@github.com"的密码:远程:计数对象:20471,完成.远程:总计 20471(增量 0),重用 0(增量 0),包重用 20471接收对象:100% (20471/20471), 812.92 MiB |4.00 MiB/s,完成.解析增量:100% (14464/14464),完成.检查连通性...完成.

$ cp -fr myrepo.git myrepo.git.bac

note2@Travel-2015-11/cygdrive/c/Users/note2/Data/git/tmpmirror$ java -jar ../bfg-1.12.12.jar --strip-blobs-bigger-than 100M myrepo.git使用回购:C:Users
ote2Datagit	mpmirrormyrepo.git大 blob 的扫描包文件:20471在 103 毫秒内完成大 blob 的包文件扫描.警告:在打包文件中找不到匹配条件的大 blob - 是否需要打包 repo?请指定 BFG 的任务:bfg 1.12.12

<小时>

攻击 #3尝试这样做会导致远程:错误:"消息:

$ git clone --mirror ../../myrepo/.git

克隆到裸仓库'myrepo.git'...完毕.

$ java -jar bfg-1.12.12.jar --strip-blobs-bigger-than 100M tmpmirror/myrepo/myrepo.git

使用 repo : C:Users
ote2Datagit	mpmirrormyrepomyrepo.git大 blob 的扫描包文件:12545在 66 毫秒内完成大 blob 的包文件扫描.找到 1 个大 blob 的 blob id - 最大 = 620441479 最小 = 620441479总尺寸(未包装)=620441479找到 1322 个要保护的对象找到 4 个指向提交的 refs:HEAD、refs/heads/master、refs/remotes/origin/HEAD、refs/remotes/origin/master受保护的提交-----------------这些是您受保护的提交,因此它们的内容不会被更改:* 提交 b68c0cbc(受HEAD"保护)打扫--------发现 2769 次提交清洁承诺:100% (2769/2769)清理提交在 1,485 毫秒内完成.更新 1 参考--------------参考之前之后-------------------------------裁判/头/主|b68c0cbc |49823acc更新参考:100% (1/1)...参考更新在 18 毫秒内完成.提交树污垢历史------------------------最早 最新||………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………D = 脏提交(文件树已修复)m = 修改提交(提交消息或父项已更改).= 干净提交(不更改文件树)之前 之后-------------------------------------第一次修改提交 |0ef7f866 |e3d74aee最后一次脏提交 |338d2b46 |01ca7b80删除的文件-------------文件名 Git id------------------------------------------------图像.eps |e12fe50b (591.7 MB)总共更改了 50 个对象 ID.完整详细信息记录在此处:C:Users
ote2Datagit	mpmirrormyrepomyrepo.git.bfg-report2016-06-1115-59-30BFG运行完成!准备好后,运行: git reflog expire --expire=now --all &&git gc --prune=now --aggressive

$ git reflog expire --expire=now --all &&git gc --prune=now --aggressive

计数对象:20681,完成.Delta 压缩最多使用 4 个线程.压缩对象:100% (20114/20114),完成.写入对象:100% (20681/20681),完成.总计 20681(增量 14625),重用 3226(增量 0)删除重复对象:100% (256/256),完成.

$ git push

计数对象:210,完成.Delta 压缩最多使用 4 个线程.压缩对象:100% (82/82),完成.写入对象:100% (210/210),1.81 MiB |0 字节/秒,完成.总计 210(增量 147),重复使用 185(增量 124)远程:错误:拒绝更新签出的分支:refs/heads/master远程:错误:默认情况下,更新非裸存储库中的当前分支远程:错误:被拒绝,因为它会使索引和工作树不一致远程:错误:使用您推送的内容,并且需要git reset --hard"来匹配远程:错误:工作树到 HEAD.远程:错误:远程:错误:您可以将receive.denyCurrentBranch"配置变量设置为远程:错误:远程存储库中的忽略"或警告"以允许推入远程:错误:它的当前分支;但是,除非您这样做,否则不建议这样做远程:错误:安排更新其工作树以匹配您推送的内容远程:错误:其他方式.远程:错误:远程:错误:要压制此消息并仍然保持默认行为,请设置远程:错误:receive.denyCurrentBranch"配置变量为拒绝".到/cygdrive/c/Users/note2/Data/git/tmpmirror/myrepo/../../myrepo/.git![远程拒绝] master ->master(分支当前已检出)错误:未能将一些引用推送到/cygdrive/c/Users/note2/Data/git/tmpmirror/myrepo/../../myrepo/.git"

解决方案

这是在git push"由于添加和提交一个大文件而卡住后我如何让它工作,然后在离开时继续提交其他工作来自网络:

我从以下位置下载了 bfg*jar:
https://rtyley.github.io/bfg-repo-cleaner/

cd tmpmirror;mkdir myrepo;cd myrepo;git clone --mirror ../../myrepo/.gitjava -jar bfg-1.12.12.jar --strip-blobs-bigger-than 100M myrepo.gitcd myrepo.git;git reflog expire --expire=now --all &&git gc --prune=now --aggressivegit push https://github.com/traildreaming/myrepocd ../../..mv myrepo myrepo_oldgit 克隆 https://github.com/traildreaming/myrepocd myrepo

如果您收到此消息,请尝试执行以下额外步骤

$ java -jar ../../bfg-1.12.13.jar --strip-blobs-bigger-than 100M myrepo.git使用回购:[DIR]	mpmirrormyrepomyrepo.git大 blob 的扫描包文件:20681在 135 毫秒内完成大 blob 的包文件扫描.警告:在打包文件中找不到匹配条件的大 blob - 是否需要打包 repo?请指定 BFG 的任务:bfg 1.12.13用法:bfg [选项] [<repo>]-b <尺寸>|--strip-blob-bigger-than <size>去除大于 X 的 blob(例如128K"、1M"等)

```

cd tmpmirror;mkdir myrepo;cd myrepo;git clone --mirror ../../myrepo/.gitcd myrepo.git;git重新打包;光盘..java -jar bfg-1.12.12.jar --strip-blobs-bigger-than 100M myrepo.gitcd myrepo.git;git reflog expire --expire=now --all &&git gc --prune=now --aggressivegit push https://github.com/traildreaming/myrepocd ../../..mv myrepo myrepo_oldgit 克隆 https://github.com/traildreaming/myrepocd myrepo

然后继续在新克隆的存储库中工作.感谢 Am 的建议我应该在镜像仓库还是原始仓库上运行 BFG? 使用git push https://github.com/traildreaming/myrepo"而不是git push".

I am in the same situation as described here after having inadvertently adding a big file that I don't want and having done additional commits of other work (not knowing the push would fail) after inadvertently adding the big file:

Am I supposed to run BFG on the mirrored repo or the original?


ATTEMPT #1 Tried this to remove the file:

git rm bigfile
git commit bigfile
git push

No luck. The push was still stuck on trying to upload the big file even though the later commit deleted it:

$ git push

Username for 'https://github.com':
Password for 'https://traildreaming@github.com':
Counting objects: 210, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (66/66), done.
Writing objects: 100% (210/210), 5.72 MiB | 1.47 MiB/s, done.
Total 210 (delta 147), reused 203 (delta 140)
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: eedddea1fcb95663492e16c14fc3a250
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File doc/image.eps is 591.70 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/traildreaming/myrepo.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/traildreaming/myrepo.git'


ATTEMPT #2 Tried the instructions for https://rtyley.github.io/bfg-repo-cleaner/

But it does not see my big files which are preventing me from doing a push:

$ git clone --mirror https://github.com/traildreaming/myrepo.git

Cloning into bare repository 'myrepo.git'...
Username for 'https://github.com':
Password for 'https://traildreaming@github.com':
remote: Counting objects: 20471, done.
remote: Total 20471 (delta 0), reused 0 (delta 0), pack-reused 20471
Receiving objects: 100% (20471/20471), 812.92 MiB | 4.00 MiB/s, done.
Resolving deltas: 100% (14464/14464), done.
Checking connectivity... done.

$ cp -fr myrepo.git myrepo.git.bac

note2@Travel-2015-11 /cygdrive/c/Users/note2/Data/git/tmpmirror
$ java -jar ../bfg-1.12.12.jar --strip-blobs-bigger-than 100M myrepo.git

Using repo : C:Users
ote2Datagit	mpmirrormyrepo.git

Scanning packfile for large blobs: 20471
Scanning packfile for large blobs completed in 103 ms.
Warning : no large blobs matching criteria found in packfiles - does the repo need to be packed?
Please specify tasks for The BFG :
bfg 1.12.12


ATTTEMPT #3 Trying this resulted in "remote: error:" messages:

$ git clone --mirror ../../myrepo/.git

Cloning into bare repository 'myrepo.git'...
done.

$ java -jar bfg-1.12.12.jar --strip-blobs-bigger-than 100M tmpmirror/myrepo/myrepo.git

Using repo : C:Users
ote2Datagit	mpmirrormyrepomyrepo.git

Scanning packfile for large blobs: 12545
Scanning packfile for large blobs completed in 66 ms.
Found 1 blob ids for large blobs - biggest=620441479 smallest=620441479
Total size (unpacked)=620441479
Found 1322 objects to protect
Found 4 commit-pointing refs : HEAD, refs/heads/master, refs/remotes/origin/HEAD, refs/remotes/origin/master

Protected commits
-----------------

These are your protected commits, and so their contents will NOT be altered:

 * commit b68c0cbc (protected by 'HEAD')

Cleaning
--------

Found 2769 commits
Cleaning commits:       100% (2769/2769)
Cleaning commits completed in 1,485 ms.

Updating 1 Ref
--------------

        Ref                 Before     After
        ---------------------------------------
        refs/heads/master | b68c0cbc | 49823acc

Updating references:    100% (1/1)
...Ref update completed in 18 ms.

Commit Tree-Dirt History
------------------------

        Earliest                                              Latest
        |                                                          |
        ...........................................................D

        D = dirty commits (file tree fixed)
        m = modified commits (commit message or parents changed)
        . = clean commits (no changes to file tree)

                                Before     After
        -------------------------------------------
        First modified commit | 0ef7f866 | e3d74aee
        Last dirty commit     | 338d2b46 | 01ca7b80

Deleted files
-------------

        Filename                     Git id
        ------------------------------------------------
        image.eps | e12fe50b (591.7 MB)


In total, 50 object ids were changed. Full details are logged here:

        C:Users
ote2Datagit	mpmirrormyrepomyrepo.git.bfg-report2016-06-1115-59-30

BFG run is complete! When ready, run: git reflog expire --expire=now --all && git gc --prune=now --aggressive

$ git reflog expire --expire=now --all && git gc --prune=now --aggressive

Counting objects: 20681, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (20114/20114), done.
Writing objects: 100% (20681/20681), done.
Total 20681 (delta 14625), reused 3226 (delta 0)
Removing duplicate objects: 100% (256/256), done.

$ git push

Counting objects: 210, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (82/82), done.
Writing objects: 100% (210/210), 1.81 MiB | 0 bytes/s, done.
Total 210 (delta 147), reused 185 (delta 124)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /cygdrive/c/Users/note2/Data/git/tmpmirror/myrepo/../../myrepo/.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/cygdrive/c/Users/note2/Data/git/tmpmirror/myrepo/../../myrepo/.git'

解决方案

Here is how I got it to work after the "git push" got stuck due to adding and committing a big file and then continuing committing with other work while away from the internet:

I downloaded bfg*jar from:
https://rtyley.github.io/bfg-repo-cleaner/

cd tmpmirror; mkdir myrepo; cd myrepo; git clone --mirror ../../myrepo/.git
java -jar bfg-1.12.12.jar --strip-blobs-bigger-than 100M myrepo.git
cd myrepo.git; git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push https://github.com/traildreaming/myrepo
cd ../../..
mv myrepo myrepo_old
git clone https://github.com/traildreaming/myrepo
cd myrepo

If you get this message, then try with the extra steps from below

$ java -jar ../../bfg-1.12.13.jar --strip-blobs-bigger-than 100M myrepo.git

Using repo : [DIR]	mpmirrormyrepomyrepo.git

Scanning packfile for large blobs: 20681
Scanning packfile for large blobs completed in 135 ms.
Warning : no large blobs matching criteria found in packfiles - does the         repo need to be packed?
Please specify tasks for The BFG :
bfg 1.12.13
Usage: bfg [options] [<repo>]

  -b <size> | --strip-blobs-bigger-than <size>
        strip blobs bigger than X (eg '128K', '1M', etc)

```

cd tmpmirror; mkdir myrepo; cd myrepo; git clone --mirror ../../myrepo/.git
cd myrepo.git; git repack; cd ..
java -jar bfg-1.12.12.jar --strip-blobs-bigger-than 100M myrepo.git
cd myrepo.git; git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push https://github.com/traildreaming/myrepo
cd ../../..
mv myrepo myrepo_old
git clone https://github.com/traildreaming/myrepo
cd myrepo

And then continue working in the newly cloned repo. Thanks to the advice at Am I supposed to run BFG on the mirrored repo or the original? to use "git push https://github.com/traildreaming/myrepo" and not "git push".

这篇关于如何从 GitHub 存储库中删除大(> 100MB)文件并成功推送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆