我应该在镜像回购或原始版本上运行BFG吗?

6 git git-rewrite-history bfg-repo-cleaner

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

我把它们放入,承诺并试图推动,但它们太大了.所以我把它们拿出来,继续工作,然后承诺,试图推,但它仍然给了我同样的错误.我认为他们仍然在历史的某个地方.

我认为我使问题变得更糟,因为我继续在那个分支工作并再做一次提交.然后我将该分支合并回主分支.

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

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

首先,

$ git clone --mirror git://example.com/some-big-repo.git
Run Code Online (Sandbox Code Playgroud)

我应该从哪里克隆?我在github.com上的远程仓库没有我提交的提交和合并,因为我添加了大文件.但是说明看起来我应该从那里得到它.(我从我当地的回购克隆.)

下一个,

$ java -jar bfg.jar --strip-blobs-bigger-than 100M some-big-repo.git
Run Code Online (Sandbox Code Playgroud)

some-big-repo.git镜像回购还是正常的本地回购?(我使用了镜像回购.)

然后我检查了我的历史记录是否已更新并尝试过,

$ cd some-big-repo.git
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
Run Code Online (Sandbox Code Playgroud)

(我在这个镜像克隆中)我收到了一个错误.

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'
Run Code Online (Sandbox Code Playgroud)

这对我来说很有意义.是的,我目前已经master检查过了.但那么,我还应该做些什么呢?如果我以另一种方式尝试,我只能看到发生的问题.

jav*_*ett 3

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

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

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

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