我不小心把一个大文件提交到我的本地git。该文件太大,无法添加到远程存储库,这使得目前无法推送我的代码。问题是,我很长一段时间没有注意到文件有多大,所以我很高兴地在文件的基础上添加了一些提交。现在,4-5提交之后,我需要在前一个提交中删除这个文件,这样我就可以将代码推送到远程存储库。
很自然,我很害怕删除一半的代码:-D
是否有任何无风险的方法来达到这一点?
发布于 2020-02-22 20:10:20
我会做的是
git rebase -i HEAD~N // where N is the number of commit you have since including
// the one where the big file added
// then deleting the first "pick" and write an "e" to edit and saving it
// then deleting the huge file
git add -A
git commit -amend // save and exit
git rebase --continue另外,如果您害怕搞砸事情,那么我所做的就是(不是必要的最佳实践)首先由git checkout -b saving创建一个保存分支,所以如果您严重地搞砸了事情,就可以从这里恢复它。
发布于 2020-02-23 03:56:40
我能建议你做的是取消你最后一次意外提交
git reset HEAD~1你可以不用你的大文件提交
https://stackoverflow.com/questions/60356194
复制相似问题