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

标签 git git-rewrite-history bfg-repo-cleaner

我想从我的 git 仓库中删除两个不再存在的文件。

我将它们放入、提交并尝试 push ,但它们太大了。所以我把它们拿出来,继续工作,然后 promise ,试图 push ,但它仍然给了我同样的错误。我认为它们仍然存在于某个地方的历史中。

我认为我让问题变得更糟了,因为我一直在那个分支工作并且又做了 1 次提交。然后我将该分支 merge 回主分支。

所以我搜索了一个解决方案并找到了bfg .

但是页面上的说明对我来说没有意义。

首先,

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

我应该从哪里克隆?我在 github.com 上的远程仓库没有我添加大文件后所做的提交和 merge 。但说明书让我觉得无论如何我都应该从那里得到它。 (我从我的本地仓库克隆。)

接下来,

$ 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。但是,我还能做什么呢?如果我尝试另一种方式,我只能看到问题发生。

最佳答案

您应该克隆/镜像您最终计划替换提交的存储库,但有一个潜在的假设,即该存储库也是一个裸存储库。这通常是一个远程存储库,但您也可以克隆一个本地存储库以节省带宽。

基本假设是,您最终将存储已清理存储库的存储库也是一个裸存储库。基于服务器的 repo 例如GitHub 通常就是这样。

在您的情况下,听起来您已经克隆了一个本地的非裸(包含 HEAD 和工作副本)存储库,以节省带宽,或者因为它是包含您希望清理的提交的存储库。无论哪种方式,为了推回非裸仓库,您需要确保您没有任何要推 check out 的引用,包括 master。

从您的评论来看,您似乎找到了解决方案,即推回最终的原始 repo ,这可能是一个裸 repo 。

关于git - 我应该在镜像仓库还是原始仓库上运行 BFG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35640859/

相关文章:

git - 如何修改特定提交?

git - 如何修改旧的 Git 提交?

bfg-repo-cleaner - bfg-repo-cleaner 可以在删除之前列出受影响的文件

git - 如何替换 git 历史文件中的文本?

git - 批量删除已经 rebase 和 merge 的本地分支

linux - 如何与连接到一台计算机的两个 beaglebone black 进行交互

git - 什么是适合 TDD 的良好 git 工作流程?

python - 使用 git 子模块或 svn :externals 在应用程序之间共享 python 模块

git - 如何使用 BFG 删除 protected 提交