blank
blank
发布于 2019-08-28 / 402 阅读 / 0 评论 / 0 点赞

git 强制删除文件 删除远程仓库中的文件

处理要删除的文件

# 用法 git filter-branch --force --index-filter "git rm --cached --ignore-unmatch 文件名" --prune-empty --tag-name-filter cat -- --all

# 比如我现在想删除 之前不小心把.gitignore文件给删除了导致推送了很多 idea的.iml文件
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch *.iml" --prune-empty --tag-name-filter cat -- --all

Rewrite dc8d6194fd93f8ae8e1d434efa8d4e26616715c4 (133/139) (99 seconds passed, remaining 4 predicted)    rm 'config-server/config-server.iml'
rm 'eureka-client/eureka-client.iml'
rm 'eureka-server/eureka-server.iml'
rm 'openfeign-consumer/openfeign-consumer.iml'
rm 'openfeign-provider/openfeign-provider.iml'
rm 'springcloud.iml'
Rewrite f235122697882400b9100b793f4edaf50308ac74 (135/139) (100 seconds passed, remaining 2 predicted)    rm 'config-server/config-server.iml'
rm 'eureka-client/eureka-client.iml'
rm 'eureka-server/eureka-server.iml'
rm 'openfeign-consumer/openfeign-consumer.iml'
rm 'openfeign-provider/openfeign-provider.iml'
rm 'springcloud.iml'
Rewrite ca8075cf3b0c09daed02c02f2dba922e024a9b3b (135/139) (100 seconds passed, remaining 2 predicted)    rm 'config-server/config-server.iml'
rm 'eureka-client/eureka-client.iml'
rm 'eureka-server/eureka-server.iml'
rm 'openfeign-consumer/openfeign-consumer.iml'
rm 'openfeign-provider/openfeign-provider.iml'
rm 'springcloud.iml'
Rewrite 41519a8e2cf2cdcd7b2d34d6e3323d40e5149f2b (137/139) (102 seconds passed, remaining 1 predicted)    rm 'config-server/config-server.iml'
rm 'eureka-client/eureka-client.iml'
rm 'eureka-server/eureka-server.iml'
rm 'openfeign-consumer/openfeign-consumer.iml'
rm 'openfeign-provider/openfeign-provider.iml'
rm 'springcloud.iml'
Rewrite 0c4ece1cd45c4ba9f869dbfe7f0d86fb7eb858c7 (137/139) (102 seconds passed, remaining 1 predicted)    rm 'config-server/config-server.iml'
rm 'eureka-client/eureka-client.iml'
rm 'eureka-server/eureka-server.iml'
rm 'openfeign-consumer/openfeign-consumer.iml'
rm 'openfeign-provider/openfeign-provider.iml'
rm 'springcloud.iml'
Rewrite bade3e9aef3657fc9a72d176be265ebbb7ec1121 (139/139) (104 seconds passed, remaining 0 predicted)    rm 'config-server/config-server.iml'
rm 'eureka-client/eureka-client.iml'
rm 'eureka-server/eureka-server.iml'
rm 'openfeign-consumer/openfeign-consumer.iml'
rm 'openfeign-provider/openfeign-provider.iml'
rm 'springcloud.iml'

Ref 'refs/heads/master' was rewritten
Ref 'refs/remotes/origin/master' was rewritten
WARNING: Ref 'refs/remotes/origin/master' is unchanged

将删除后的结果强制推送到远程仓库

git push origin --force --all

Enumerating objects: 430, done.
Counting objects: 100% (430/430), done.
Delta compression using up to 8 threads
Compressing objects: 100% (373/373), done.
Writing objects: 100% (411/411), 60.09 KiB | 1.43 MiB/s, done.
Total 411 (delta 219), reused 0 (delta 0)
remote: Resolving deltas: 100% (219/219), completed with 6 local objects.
To http://url.git
 + bade3e9...ff87e5a master -> master (forced update)

操作完成后可以在git网站中确认下是否已经完全删除成功

参见


评论