gpt4 book ai didi

Git - 如何从提交历史中删除一个大文件以便我可以推送存储库?

转载 作者:太空狗 更新时间:2023-10-29 13:43:22 27 4
gpt4 key购买 nike

几个月前,我不小心将一个大约 100MB 的目录提交到我的存储库。

快进到今天,我正在尝试将该存储库迁移到 Github。由于大小限制,它不会让我。

我已经使用以下帖子删除了该目录:Completely remove file from all Git repository commit history

它似乎有效,但整个项目仍然有 100M 的重量。我运行了 du . 并得到以下行:98M ./.git/objects

我不确定如何解决这个问题,因为我已经尝试了一些解决方案,但似乎都不起作用。

我现在该怎么办?

编辑:我设法使用上面链接的线程修复了它。特别是 Darren 的回答。

最佳答案

我设法使用上面链接的线程修复了它。具体来说,我做了类似于 Darren 的回答的事情。为了您的方便,我把它放在这里:

This is the best way:
http://github.com/guides/completely-remove-a-file-from-all-revisions

Just be sure to backup the copies of the files first.

EDIT

The edit by [Neon][1] got unfortunately rejected during review. See Neons post below, it might contain useful information!

[1]: https://stackoverflow.com/users/309261/neon


E.g. to remove all *.gz files accidentally committed into git repository:

$ du -sh .git ==> e.g. 100M
$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch *.gz' HEAD
$ git push origin master --force
$ rm -rf .git/refs/original/
$ git reflog expire --expire=now --all
$ git gc --prune=now
$ git gc --aggressive --prune=now

That still didn't work for me? (I am currently at git version 1.7.6.1)

$ du -sh .git ==> e.g. 100M

Not sure why, since I only had ONE master branch. Anyways, I finally got my git repo truely cleaned up by pushing into a new empty and bare git repository, e.g.

$ git init --bare /path/to/newcleanrepo.git
$ git push /path/to/newcleanrepo.git master
$ du -sh /path/to/newcleanrepo.git ==> e.g. 5M

(yes!)

Then I clone that to a new directory and moved over it's .git folder into this one. e.g.

$ mv .git ../large_dot_git
$ git clone /path/to/newcleanrepo.git ../tmpdir
$ mv ../tmpdir/.git .
$ du -sh .git ==> e.g. 5M

(yeah! finally cleaned up!)

After verifying that all is well, then you can delete the ../large_dot_git and ../tmpdir directories (maybe in a couple weeks or month from now, just in case...)

简而言之:我过滤了分支,创建了一个新的裸仓库,将 master 推送到它,将其克隆到一个新目录中,并将我项目的 git 目录替换为克隆中的 git 目录。

关于Git - 如何从提交历史中删除一个大文件以便我可以推送存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25550597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com