git filter-branch应用

1.修改author和committer

git filter-branch --commit-filter '
export GIT_AUTHOR_EMAIL=me@example.com;
export GIT_AUTHOR_NAME=me;
export GIT_COMMITTER_EMAIL=me@example.com;
export GIT_COMMITTER_NAME=me;
git commit-tree "$@"
'

2.删除误提交的文件

a.用git filter-branch对所有分支上的commit执行命令操作,忽略对该文件的追踪,
将其从git仓库中移除,并重写每一条记录

//从指定的commit中删除误操作文件的记录
git filter-branch --tree-filter 'git rm -f --ignore-unmatch {{文件名}}' [commit1..commit2]

//从当前分支的前30次提交开始遍历,删除误操作文件的引用
git filter-branch --tree-filter 'git rm -f {{文件名}}' HEAD~30..HEAD

b.强制推送到远端

git push origin master --force

出处:https://walterlv.oschina.io/git/2017/09/19/delete-file-using-filter-branch.html
出处:http://www.jianshu.com/p/099e644b60fb

原文地址:https://www.cnblogs.com/mengff/p/7852694.html