Skip to content

Instantly share code, notes, and snippets.

@austinhappel
Last active July 12, 2016 14:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinhappel/4771583 to your computer and use it in GitHub Desktop.
Save austinhappel/4771583 to your computer and use it in GitHub Desktop.
A few different ways to delete all .svn files from a git repository's history.
#!/bin/python
# USAGE:
# 1) cd /path/to/git/repository
# 2) execute the script with: `python /path/to/remove_svn.py`
# NOTE: By default this code does a dry-run. To actually delete files from history, remove the
# "n" flag from the 'git rm -rfn' around line 20.
import subprocess
p = subprocess.Popen(['find', '.', '-name', '*.svn'], stdout=subprocess.PIPE)
svnlist, err = p.communicate()
files = ''
for filepath in svnlist.split('\n'):
if filepath and filepath != '\n':
q = subprocess.Popen(['git', 'filter-branch', '-f', '--index-filter',
str('git rm -rfn --cached --ignore-unmatch ' + filepath),
'--prune-empty'],
stdout=subprocess.PIPE)
out, err = q.communicate()
print out
# Usage:
# 1) cd /path/to/git/repository
# 2) paste this code and run.
# NOTE: By default this does a dry-run. Remove the "n" flag from the 'git rm -rfn' near the
# the end of the line to really delete history.
find . -name '*.svn' | xargs -I {} git filter-branch -f --prune-empty --index-filter "git rm -rfn --cached --ignore-unmatch {}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment