从 git repo 中完全删除文件(从某个时间点开始)

发布于 2024-11-17 00:16:42 字数 199 浏览 6 评论 0原文

我有一个大约有 2030 次提交的存储库。在提交 2000 左右时,一个文件被修改,导致其大小意外从大约 20M 变为 1.2 GB。是否可以重写历史记录以删除此文件,但只能从提交 2000 中删除? (我不想丢失该文件的先前历史记录)

我正在考虑 git-filter-branch,但找不到一种方法来告诉它“来自提交” - 有可能吗?

干杯 麦克风

I've got a repo with about 2030 commits. At around commit 2000 a file was modified which caused it's size to travel from about 20M to 1.2 GB accidently. Is it possible to rewrite the history to remove this file but only from commit 2000? (I dont want to lose prior history of this file)

I was thinking git-filter-branch, but couldnt see a way to tell it the "from commit" - is it possible?

Cheers
Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤单情人 2024-11-24 00:16:42

git-filter-branch 的手册页包含了这方面结论性且权威的示例。

如果您想在某个提交之前停止重写,请在 tag01 之前说:

git-filter-branch ......  -- master ^tag01

用已有的内容替换点。 tag01 可能是任何 commit-ish (revspec)

PS: 如果你使用标签,不要忘记 --tag-name-filter cat 来重写它们

The man page for git-filter-branch contains the conclusive and authoritative example for this.

If you want to stop rewriting before a certain commit, say before tag01:

git-filter-branch ......  -- master ^tag01

Substitute what you already have for the dots. tag01 may instead be any commit-ish (revspec)

PS: if you use tags don't forget --tag-name-filter cat to rewrite these too

美人骨 2024-11-24 00:16:42

为什么不在

  1. 提交 2000 处创建一个分支 new,并且不将此文件修改为 1.2 GB 文件
  2. master 重新设置为 new,使用合并选项-Xtheirs
  3. 垃圾收集存储库以节省磁盘空间。

Why won't you

  1. Create a branch new at commit 2000, where you don't modify this file to a 1.2 GB file
  2. Rebase master to new, with merge option -Xtheirs
  3. Garbage collect the repository to save disk space.
迷爱 2024-11-24 00:16:42

您可能想尝试 BFG Repo-Cleaner,它是 < code>git-filter-branch 设计用于从 Git 存储库中删除大文件或私有数据。

下载可执行 jar(需要 Java 6 或更高版本)并运行以下命令:

$ java -jar bfg.jar --strip-blobs-bigger-than 100MB my-repo.git

任何大小超过 100MB 的内容(不在您的最新提交的文件层次结构中)都将被完全删除从您的存储库的历史记录中。正如问题中所指定的,所有小于 100MB 的文件版本都将被保留。

全面披露:我是 BFG Repo-Cleaner 的作者。

You might want to try the BFG Repo-Cleaner, a faster, simpler alternative to git-filter-branch designed for removing large files or private data from Git repos.

Download the executable jar (requires Java 6 or above) and run this command:

$ java -jar bfg.jar --strip-blobs-bigger-than 100MB my-repo.git

Anything over 100MB in size (that isn't in your latest commit's file hierarchy) will be totally removed from your repository's history. All the versions of the file which are smaller than 100MB will be left alone, as specified in the question.

Full disclosure: I'm the author of the BFG Repo-Cleaner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文