想要彻底删除 Git 仓库中的某个文件或文件夹(包括历史记录)时,可以按照以下步骤操作:
如果要删除文件,使用以下命令:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch 文件名' --prune-empty --tag-name-filter cat -- --all
如果要删除文件夹,使用以下命令:
git filter-branch --force --index-filter 'git rm --cached -r --ignore-unmatch 文件夹名/' --prune-empty --tag-name-filter cat -- --all
如果要删除某个文件夹下所有以“2018”开头的 mp4 文件,可以使用类似的命令:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch 文件夹名/2018*.mp4' --prune-empty --tag-name-filter cat -- --all
git push -u origin master -f
删除回收:
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
这些步骤经过测试,可以成功地删除文件或文件夹及其历史记录。
记得在执行这些操作之前,先备份仓库数据,以防丢失。
未经允许不得转载:前端资源网 - w3h5 » 彻底删除Git仓库中的某个文件或文件夹(包括历史记录)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有