如何从GitHub存储库中删除大(>;100MB)文件并成功推送?

如何从GitHub存储库中删除大(>;100MB)文件并成功推送?,git,github,bfg-repo-cleaner,Git,Github,Bfg Repo Cleaner,在无意中添加了一个我不想要的大文件,并且在无意中添加了大文件后,我又做了其他工作(不知道推送会失败),我的情况与这里描述的相同: 尝试#1 尝试此操作以删除文件: git rm bigfile git commit bigfile git push 不走运。尽管稍后的提交删除了大文件,但推送仍无法尝试上载该文件: $git推送 Username for 'https://github.com': Password for 'https://traildreaming@github.com'

在无意中添加了一个我不想要的大文件,并且在无意中添加了大文件后,我又做了其他工作(不知道推送会失败),我的情况与这里描述的相同:


尝试#1 尝试此操作以删除文件:

git rm bigfile
git commit bigfile
git push
不走运。尽管稍后的提交删除了大文件,但推送仍无法尝试上载该文件:

$git推送

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'
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'

尝试#2 我试了一下说明书

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

$git克隆--镜像

$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\note2\Data\git\tmpmirror\myrepo.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

ATTEST#3 尝试此操作会导致“远程:错误:”消息:

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

Cloning into bare repository 'myrepo.git'...
done.
Using repo : C:\Users\note2\Data\git\tmpmirror\myrepo\myrepo.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\note2\Data\git\tmpmirror\myrepo\myrepo.git.bfg-report\2016-06-11\15-59-30

BFG run is complete! When ready, run: git reflog expire --expire=now --all && git gc --prune=now --aggressive
$java-jar bfg-1.12.12.jar——去除大于100M的斑点tmpmerror/myrepo/myrepo.git

Cloning into bare repository 'myrepo.git'...
done.
Using repo : C:\Users\note2\Data\git\tmpmirror\myrepo\myrepo.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\note2\Data\git\tmpmirror\myrepo\myrepo.git.bfg-report\2016-06-11\15-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推送

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'
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'

即使您在最新提交中删除了该文件,您的历史记录中仍有该文件的副本。我想你会想把它从git中完全删除

你可能会想重新调整它的基调。要了解您何时介绍它,您可以执行以下操作:

git log --reverse -n1 doc/image.eps
然后复制它提供给您的SHA,并进行交互式重设基础:

git rebase -i sha~1
保留上述命令中的
~1
,但将
sha
替换为先前命令输出中的实际sha。如果上述命令不起作用,您可能需要设置
编辑器
,例如:

EDITOR=vim git rebase -i sha~1
vim
替换为您熟悉的任何命令行编辑器(
emacs
nano
,等等)。您可以让它与GUI编辑器(如
atom
)一起工作,但您可能需要传入额外的参数,以强制进程等待关闭窗口。如果使用atom,则可以运行:

EDITOR="atom --wait" git rebase -i sha~1
这会让你回到过去。第一行将有
选择
。您将需要将其更改为
编辑
。然后保存并退出编辑器。不要更改任何其他
pick
s

这将使您回到引入大文件的提交阶段。您现在可以从git中删除它:

git rm doc/image.eps && git commit --amend
然后继续重设基础:

git rebase --continue
如果这一切都完成了,那么你就完蛋了。您应该能够
git推送
。但是,如果没有,那么您可能已经在以后的提交中更新了映像。您需要执行与上面每次停止时相同的
git rm doc/image.eps&&git commit--amend&&git rebase--continue

我假设了很多东西,所以我希望您对git、编辑器和命令行足够熟悉,可以使用这些信息


另外,可能有一种更短更简洁的方法可以做到这一点,但既然你问了这个问题,我假设你不想要一个神奇的
git
命令,它会自己撕毁你的历史。首先,让我们一步一步地尝试一下。

以下是在“git推送”由于添加和提交一个大文件而受阻后,我是如何让它工作的,然后在远离互联网的情况下继续提交其他工作:

我从以下网站下载了bfg*jar:

如果您收到此消息,请尝试下面的额外步骤

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

Using repo : [DIR]\tmpmirror\myrepo\myrepo.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)

然后继续在新克隆的回购协议中工作。多亏了上的建议,使用“git push”而不是“git push”。

我认为它现在起作用了。我不应该在“git-push”的“trunt#3”上停止,我尝试了我链接到的stackoverflow答案中建议的操作:“git-push”,而不是“git-push”。然后我去了一个空目录,克隆了我的repo。另一个回答中的人说东西不见了。我不确定是否有东西丢失了。乍一看还行。如果没有,将更新w/详细信息。