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

6
我想从我的git仓库中删除两个已经不存在的文件。
我将它们放进去,提交了,试图推送,但它们太大了。所以我把它们拿出来,继续工作,然后提交,尝试推送,但它仍然给我同样的错误。我想它们还在历史记录中。
我认为我让问题变得更糟了,因为我在那个分支上继续工作,并做了1次提交。然后我将该分支合并回主分支。
所以我搜索了解决方案,找到了bfg
但页面上的说明对我来说没有意义。
首先,
$ git clone --mirror git://example.com/some-big-repo.git

我应该从哪里克隆?我的github.com上的远程仓库没有我添加大文件后所做的提交和合并。但是指示似乎让我从那里获取它。(我从本地仓库克隆了)。
接下来,
$ java -jar bfg.jar --strip-blobs-bigger-than 100M some-big-repo.git

“some-big-repo.git”是镜像仓库还是普通本地仓库?(我使用了镜像仓库。)

然后我检查了我的历史记录已经更新并尝试了:

$ cd some-big-repo.git
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive

我在镜像克隆中遇到了一个错误。

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 /home/cole/main_repo
 + 94b9a0d...c7c4317 work -> work (forced update)
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/home/cole/main_repo'

这对我很有意义。是的,我目前已经检出了master。但是,我应该做什么其他的呢?如果我尝试其他方法,我只能看到问题的发生。

我实际上以一种令人惊讶的简单方式使其工作。我只需要执行 git push https://github.com/<远程>。然后它就不会尝试推送到本地 repo 并给我那些错误。但是当我从 repo 拉取一个新的克隆时,有些东西丢失了。我只需从我的本地 repo 添加它们并提交和推送即可。现在我很清爽。希望这就是它应该工作的方式。 - user4084811
2个回答

3
你应该克隆/镜像最终计划替换提交的repo,但有一个基本假设,即这个repo也是一个裸repo。这通常是一个远程repo,但你也可以克隆一个本地repo以节省带宽。
基本假设是,你最终存储清理后的repo的repo也是一个裸repo。基于服务器的repo,如GitHub通常正是如此。
在你的情况下,听起来你已经克隆了一个本地的、非裸的(包含一个HEAD和工作副本)repo,无论是为了节省带宽还是因为它是包含你想要清理的提交的repo。无论哪种方式,为了推回到一个非裸的repo,你需要确保你没有任何想要推送的引用被签出,包括master。
从你的评论中看来,你找到了解决方案,就是将其推回到最终的origin repo,这很可能是一个裸repo。

3

BFG的前三个步骤:

  1. Download BFG using the following command in terminal: brew install bfg
  2. Clone a fresh copy of your repo, using the --mirror flag.

    git clone --mirror git://example.com/some-big-repo.git
    

    The mirror flag allows you to make a full copy of the Git database without actually copying down the files of the repo.

  3. bfg --the-options-you-want the-mirror-repo-you-just-cloned.git

本文翻译自IBM工程师的使用BFG Repo Cleaner工具从git仓库中删除敏感文件的手册。请注意,在第3步中不要进入存储库,否则会出现错误“the-mirror-repo-you-just-cloned.git不是有效的Git存储库”。


对于那些在 reflog 和 prune 上遇到“fatal: not a git repository”消息的人,你需要进入克隆目录,然后再深入一层进入 myrepo.git 目录。当你进入这个目录时,在 Bash 中会显示 (Bare:master)。然后 reflog 和 prune 就可以正常工作了。 - micstr
它告诉我这不是一个有效的代码库。我当时在代码库里面。你不应该在代码库里面。 - Aswin Prasad

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