Skip to content

Instantly share code, notes, and snippets.

@selckin
Created May 28, 2019 09:23
Show Gist options
  • Save selckin/c5ccfd5fb5f4c9f3bafb55c665cfb6f5 to your computer and use it in GitHub Desktop.
Save selckin/c5ccfd5fb5f4c9f3bafb55c665cfb6f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# git filter-branch --index-filter 'git rm --ignore-unmatch -r --cached ":(exclude)foo"' --prune-empty -- --all
pattern="$1"
[[ -z ${pattern} ]] && exit 1
git filter-branch --index-filter "git rm --cached --ignore-unmatch ${pattern}" --tag-name-filter cat -f -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment