【问题标题】:How to delete folder from git history permanently using BFG如何使用 BFG 从 git 历史记录中永久删除文件夹
【发布时间】:2019-05-27 17:21:18
【问题描述】:

我正在使用 BFG 删除我的两个文件夹。从回购开始就对它们进行了跟踪。删除的原因是那些文件夹包含我们不再需要的二进制文件和其他 txt 文件。但是当我尝试删除这两个文件夹时,一个被删除了,但另一个仍然存在。

我创建了我的虚拟仓库并做了一些提交来重现问题。 我假设 myRepo.git 一开始就是干净的仓库。

我用来删除文件夹的功能是: java -jar bfg-1.13.0.jar --no-blob-protection --delete-folders "{system1, system2}" myRepo.git

#!/bin/bash


BUILD(){
  git clone https://github.com/xxxx/myRepo.git
  cd myRepo
  echo "Jpt test1" > jpt1.txt
  echo "Jpt test2" > jpt2.txt
  echo "Jpt test3" > jpt3.txt

  git add jpt1.txt jpt2.txt jpt3.txt
  git commit -m "first commit"
  git push origin master
  ######
  mkdir system1
  cd system1
  mkfile 14m outputfile1.out
  mkfile 14m outputfile2.out
  echo "Jpt test1" > sysjpt1.txt
  echo "Jpt test2" > sysjpt2.txt
  echo "Jpt test3" > sysjpt3.txt
  cd ..
  ######
  mkdir system2
  cd system2
  mkfile 14m outputfile1.out
  mkfile 14m outputfile2.out
  cd ..

  git add system1 system2
  git commit -m "tracking large file"
  git push origin master
  cd ..

  ##### Call function BFG which does BFG stuff. 
  BFG

}

BFG(){
  # run bfg and let git clean history 

  git clone --mirror https://github.com/xxxx/myRepo.git

  java -jar bfg-1.13.0.jar --no-blob-protection --delete-folders "{system1, system2}" myRepo.git 

  cd myRepo.git
  git reflog expire --expire=now --all && git gc --prune=now --aggressive
  git push 

  cd ..
  mkdir test_new
  cd test_new
  git clone https://github.com/xxx/myRepo.git
  cd myRepo
  ls


}

BUILD

当我在清理后克隆并对其执行ls 时。我明白了 jpt1.txt jpt2.txt jpt3.txt system2。看看 system2 文件夹如何仍然存在。

【问题讨论】:

  • 澄清一下,system2 还在,但文件还在吗?另外,我不喜欢"{system1, system2}"。通过在其周围加上引号,您将该字符串按原样传递给 bfg,而不是让 shell 扩展它。逗号后面的空格也似乎是个坏主意。您是否尝试过在两个命令中运行它,每个文件夹一个?
  • 是的,其他文件也在那里。我会尝试你的建议并让你知道。
  • @joanis 所以我试着像你说的那样,分开做它们,它起作用了。正如您所说,问题可能出在脚本的"{system1, system2}" 部分。
  • 在使用命令java -jar bfg-1.13.0.jar --no-blob-protection --delete-folders "{system1, system2}" myRepo.git 进行更多操作并重新阅读您的评论The space after the comma also seems like a bad idea. 之后。我试过没有空间,它似乎工作。所以我可以确认空间是问题所在。所以我运行的最后一个命令是java -jar bfg-1.13.0.jar --no-blob-protection --delete-folders "{system1,system2}" myRepo.git 看看现在有多少空间 `"{system1,system2}"。
  • 好的,谢谢你告诉我。那我把它写下来作为答案。

标签: git bfg-repo-cleaner


【解决方案1】:

正如您根据我在上述 cmets 中的建议所测试的那样,问题在于 "{system1, system2}" 中的空格。处理该表达式时,它会将其扩展为 "system1"" system2",,在 system2, 前面有一个空格,这不是您想要的。

您可以在两个命令中运行该过程,一次使用system1,一次使用system2,,或者直接删除空格,一切都会奏效。

有趣的是,{a,b} 的扩展似乎是由 bfg 本身完成的,而不是由 bash:引号告诉 bash 按字面意思传递该字符串,因此虽然这看起来像 bash 语法,但它实际上不是 bash 扩展。

【讨论】:

    猜你喜欢
    • 2013-08-03
    • 2013-03-24
    • 2017-10-01
    • 2014-11-20
    • 2019-11-14
    • 2014-06-19
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多