Don’t do it. Just don’t.
But suppose someone commits and then reverts a branch with a million files in it. It happens /vendor – I’m looking at you, here.
- Make sure your local repo has all the same branches as the remote and that they all track.
git config --add remote.origin.push '+refs/tags/*:refs/tags/*' git config --add remote.origin.push '+refs/heads/*:refs/heads/*'
for remote_branch in `git branch --all | grep -v HEAD | sed -e 's/\*//'`; do local_branch=`echo $remote_branch | sed -e 's!remotes/origin/!!'`; git checkout $local_branch; done
- now get the commit hashes for the commits you need to remove – for example, 2 commits
git filter-branch --commit-filter ' case $GIT_COMMIT in 862ff2e9fc5926646bb9381e1a977c806e6f3e9e|862ff2e9fc5926646bb9381e1a977c806e6f3e9e) skip_commit "$@" ;; *) git commit-tree "$@" ;; esac' --tag-name-filter cat -- --all; git reflog expire --expire=now --all; git gc --aggressive --prune=now
- force push
- repeat in each branch