Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 我应该在镜像回购或原始回购上运行BFG吗?_Git_Git Rewrite History_Bfg Repo Cleaner - Fatal编程技术网

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

Git 我应该在镜像回购或原始回购上运行BFG吗?,git,git-rewrite-history,bfg-repo-cleaner,Git,Git Rewrite History,Bfg Repo Cleaner,我想从我的git repo中删除两个不再存在的文件 我把它们放进去,承诺,并试图推动,但它们太大了。所以我把他们拿出来,继续工作,然后承诺,试图推动,但它仍然给了我同样的错误。我想他们还在某个地方的历史上 我想我把问题弄得更糟了,因为我一直在那个部门工作,并且又做了1次承诺。然后,我将该分支合并回主分支 所以我寻找一个解决方案并找到了答案 但是这一页上的说明对我来说没有意义 首先 $ git clone --mirror git://example.com/some-big-repo.git

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

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

我想我把问题弄得更糟了,因为我一直在那个部门工作,并且又做了1次承诺。然后,我将该分支合并回主分支

所以我寻找一个解决方案并找到了答案

但是这一页上的说明对我来说没有意义

首先

$ git clone --mirror git://example.com/some-big-repo.git
我应该从哪里克隆?我在github.com上的远程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,但也可以克隆本地repo以节省带宽

基本假设是,您最终将存储清理后的存储库的回购协议也是裸回购协议。基于服务器的repo(例如GitHub)通常正是如此

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


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

BFG的前3个步骤:

  • 在终端中使用以下命令下载BFG:
    brew安装BFG
  • 使用
    --mirror
    标志克隆回购协议的新副本

    git clone --mirror git://example.com/some-big-repo.git
    
    镜像标志允许您创建Git数据库的完整副本,而无需实际复制repo的文件

  • bfg——您想要刚刚克隆的镜像回购的选项。git


  • 改编自。不要像第3步所说的那样将cd
    放入repo,否则会出现错误“the-mirror-repo-you-just-cloned.git不是有效的git存储库。”

    实际上,我用一种非常简单的方式让它工作。我只需要做git推送https://github.com/
    。然后,它没有试图推动本地回购协议,并给我这些错误。但当我从repo公司提取一个新的克隆人时,它遗漏了一些东西。我只是从我的本地回购协议中添加了它们,并承诺和推动。现在我又干净又干净了。我希望这就是它应该如何工作的。对于那些陷入困境的人来说,这是致命的:在reflog和prune上没有git存储库消息。您需要在克隆的目录中进行搜索,然后深入到
    myrepo.git
    目录。当您进入这个目录时,您将在Bash中看到它说
    (Bare:master)
    。然后reflog和prune就可以工作了。它告诉我它不是一个有效的存储库。我在回购协议里面。你不应该在回购协议中。
    git clone --mirror git://example.com/some-big-repo.git