Git 挽救你的 Git 仓库

tim_lang · 2016年07月25日 · 最后由 zj0713001 回复于 2016年07月26日 · 7755 次阅读

事情是这样的,新来的前端小妹对 git 不熟悉,然后使用了 git add 提交了当前目录下 vagrant 的 box,大概有 1G 多。

于是噩梦来了,rails 部署大家都知道的,都是要先从 git 仓库更新代码的。即使删除了 1G 多的 box,这个记录还是会存在 git 的 history 里面的,也就是说每个服务器发布时候必须要先更新 1G 多的 history。

google 后发现其实发现早是很好解决的:

git rm --cached giant_file

git commit --amend -CHEAD

git push

如果不幸这条大文件的提交在你的历史 commits 中的话也没关系,有人做了个工具来解决这个事情:https://github.com/rtyley/bfg-repo-cleaner

新人居然没有Code Review,差评

这工具不错,赶紧收藏了。

#1 楼 @justin Review 之前不是要 commit & push 么?不提交怎么 review 😏

#3 楼 @hz_qiuyuanxin 用 github 或 gitlab 的话可以 fork, pull request

前端小妹立了一功,代我谢谢她😂

真巧,以前也碰到过。不过那是前端小哥,最后流程跟你一样。

要这么麻烦吗?回到某个 commit,做一下 amend 然后 rebase 后续 commits 再 force push 不就好了……

#3 楼 @hz_qiuyuanxin 在自己的仓库 review 啊 怎么能 push 到主仓库。。。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号