git删除提交

不小心将编译中间文件push到服务器了,下面几步纪录了彻底删除指定文件的方法。谨慎使用。

  • 1、从资料库中清除文件

    git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch projects/Moon.mp3' --prune-empty  --tag-name-filter cat -- --all
    
  • 2、 推送我们修改后的repo

    git push origin master --force
    
  • 3、清理和回收空间

    rm -rf .git/refs/original/
    
    git reflog expire --expire=now --all
    
    git gc --prune=now
    
    git gc --aggressive --prune=now
    

猜你喜欢

转载自blog.csdn.net/iamdy/article/details/45899099