且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从git历史中删除大文件?

更新时间:2023-12-04 20:23:04

如果我找到你的话,rebasing之后你想做 git push -f origin 而不是 git pull 。这会按照预期重写远程回购记录。



注意强制推送到共享存储库可能会抹去其他人的更改,并且只应在授予每个人都可以访问。
此外,我建议您确保将来可以访问 origin / master 的废弃历史记录(通过标记它或类似内容),至少直到大家都同意这个rebase成功了。

We have a remote git repository where there are no size restrictions for files and we had pushed a 300MB into it. We then realized it and then removed the file from the repository.

Meanwhile the same repository was added to github and when we try to push the changes to github, we get the large file size error.

remote: error: File dir/filename is 312.27 MB; this exceeds GitHub's file size limit of 100 MB

To fix this, I tried using the interactive git rebase solution suggested at How to remove/delete a large file from commit history in Git repository?, but at the end of the rebase operation I end up with the following when I do git status

[18:10:35] $ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 8 and 24 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

And if I use git pull then all the changes which I have removed are brought back to the git repository. How do I fix this?

If I get you right, after rebasing you want to do git push -f origin instead of git pull. This rewrites the remote repos history as intended.

ATTENTION Force pushing to a shared repository potentially wipes other people's changes and should only be done after confering with everyone having access. Additionally I'd suggest to make sure you can access the discarded history of origin/master in the future (by tagging it or something similar), at least until everybody agrees the rebase worked out fine.