删除存储库中特定文件的所有先前版本。只保留最新的。

huangapple go评论56阅读模式
英文:

Remove all previous versions of certain files in a repository. Only keep the latest

问题

我有一个包含许多二进制文件的存储库,其中有多个版本已提交并推送。我只想保留所有这些文件的最新版本。

可以强制推送是可以的。我是这个项目上唯一的工作人员。

我还有本地更改,我也不想丢失。它们尚未提交。

英文:

I have a repo with many binary files that had several versions commited and pushed. I want to keep only the latest version of all those files.

It's ok to force a push. I'm the only one working on this project.

I have local changes I don't want to lose too. They aren't commited yet.

答案1

得分: 2

你的任务并不那么琐碎,但我建议你使用BFG Repo-Cleaner

正如你在文档中所看到的,它可以对存储库执行许多操作,例如删除符合你想要的任何条件的文件,但最重要的是以下内容:

您当前的文件是神圣的...

默认情况下,BFG 不会修改您的主分支(或 'HEAD' 分支)上的最新提交的内容,尽管它将清理掉它之前的所有提交。

这是因为您最新的提交很可能是您部署到生产环境的提交,而仅仅删除私有凭据或大文件很可能会导致损坏的代码,不再包含它所期望的硬编码数据 - 您需要修复这个问题,BFG 不能为您执行此操作。一旦您提交了您的更改 - 并且您的最新提交不包含任何不需要的数据 - 您可以运行 BFG 来执行其简单的删除操作,覆盖所有历史提交。

通过它,您可以删除匹配某些条件的 Blob,但保留最新版本。

此外,请记住,BFG 会在本地创建一个第二个仓库,因此它不会更改主仓库中的任何内容。如果一切按您的预期进行,您可以强制推送到远程服务器。

英文:

Your task it is not so trivial, but I would suggest you to use BFG Repo-Cleaner.

As you can see reading the documentation, it can do many operation on repositories, for example remove files matching any criteria you want, but the most important thing is the following:

> Your current files are sacred...
>
> By default the BFG doesn't modify the
> contents of your latest commit on your master (or 'HEAD') branch, even
> though it will clean all the commits before it.
>
> That's because your latest commit is likely to be the one that you
> deploy to production, and a simple deletion of a private credential or
> a big file is quite likely to result in broken code that no longer has
> the hard-coded data it expects - you need to fix that, the BFG can't
> do it for you. Once you've committed your changes- and your latest
> commit is clean with none of the undesired data in it - you can run
> the BFG to perform it's simple deletion operations over all your
> historical commits.

Thanks to it you could remove blob matching some conditions, but keeping the latest version.

Further, keep in mind that BFG creates a second repo locally, so it does not change anything in your main repo. If all goes as you expect you can push forced to the remote server.

huangapple
  • 本文由 发表于 2023年7月10日 15:03:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76651374.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定