从 git repo 中完全删除文件(从某个时间点开始)
我有一个大约有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
git-filter-branch 的手册页包含了这方面结论性且权威的示例。
如果您想在某个提交之前停止重写,请在
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
: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为什么不在
new
,并且不将此文件修改为 1.2 GB 文件master
重新设置为new
,使用合并选项-Xtheirs
Why won't you
new
at commit 2000, where you don't modify this file to a 1.2 GB filemaster
tonew
, with merge option-Xtheirs
您可能想尝试 BFG Repo-Cleaner,它是 < code>git-filter-branch 设计用于从 Git 存储库中删除大文件或私有数据。
下载可执行 jar(需要 Java 6 或更高版本)并运行以下命令:
任何大小超过 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:
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.