查看暂存区
git ls-files
从暂存区删除指定文件
git rm --cached <文件名>
清空暂存区的所有文件
rm .git/index
有时候明明暂存区里没有的大文件也会被上传,然后报错,今天被折磨了一个下午(꒦ິ^꒦ິ)。报错如下
remote: Resolving deltas: 100% (2/2), done.
remote: error: Trace: f51694da0a32cdb084515726bf3f6935d4394d73469ed193fcc16ee9a0a98757
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File data_stand.csv is 527.52 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To github.com:xxxxxxxxx <my repository>.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'github.com:xxxxxxxxx <my repository>.git'
当时注意力全在 ! [remote rejected] master -> master (pre-receive hook declined)
上,然后研究了好久gitlab和protected branch…如果是因为branch受保护没办法push可以参考这个:https://stackoverflow.com/questions/28318599/git-push-error-pre-receive-hook-declined
然后才发现只是不知道为什么明明暂存区里没有的文件也被push了,解决办法就是把报错的data_stand.csv
给忽略掉再push就好了(第二遍push可以用git push origin master -f
强制push):
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch data_stand.csv'