Last active
July 12, 2016 14:41
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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