删除大文件后git push

Dan*_*iel 6 git

我不小心提交了log/test.log但从未推过它.我已经完成了一个git rm来摆脱它.但是当我尝试推送时,我仍然会收到大量试图传输的数据.不应该git rm解决这个问题.如果没有,我该如何解决?

Gre*_*con 11

不要还原提交然后推送,因为巨大的文件仍将在历史记录中携带.

鉴于您尚未推送它并且您想要重做的提交是最新的,请从历史记录中删除该提交:

$ git reset HEAD^

这将使您的索引返回到它在父commit(HEAD^)上的状态.现在你有一个重新调整:第一次添加和提交你的意思.

如果您已经进行了其他后续提交,则需要将错误提交的父级的SHA-1 git rebase -i <commit>放在何处<commit>.

例如(注意SHA-1在你的回购中会有所不同)

$ git rebase -i 57d0b28

会把你放在一个类似的编辑器中

pick 366eca1 This has a huge file
pick d975b30 delete foo
pick 121802a delete bar

# Rebase 57d0b28..121802a onto 57d0b28
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

更换pickedit上线与重承诺

edit 366eca1 This has a huge file
pick d975b30 delete foo
pick 121802a delete bar

保存并退出编辑器以返回到shell,在那里您将看到表单的消息

Stopped at 366eca1... This has a huge file
You can amend the commit now, with

    git commit --amend

Once you are satisfied with your changes, run

    git rebase --continue

从那里,删除有问题的文件(--cached仅从索引中删除文件)

$ git rm --cached big-nasty-file
rm 'big-nasty-file'

修改提交

$ git commit --amend

并完成rebase

$ git rebase --continue