-
Notifications
You must be signed in to change notification settings - Fork 7
/
clean_from_git_history
executable file
·30 lines (23 loc) · 1.24 KB
/
clean_from_git_history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env bash
set -o errexit
# Copied over from: http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/
# Author: David Underhill
# Script to permanently delete files/folders from your git repository. To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2
# Note: There are other gists, etc that can help achieve the same. One such script can be found here: https://gist.github.com/kevinwright/a3d2efe2ce6ca48825ce - not sure which is more "up-to-date" and can be better used for solving your problem. YMMV
if [ $# -eq 0 ]; then
echo "Usage: $0 <files to be deleted>"
echo " You can specify multiple files to be deleted - just separate them with a space in between"
exit 1
fi
# make sure we're at the root of git repo
if [ ! -d .git ]; then
echo "Error: must run this script from the root of a git repository"
exit 1
fi
# remove all paths passed as arguments from the history of the repo
files=$@
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD
# remove the temporary history git-filter-branch creates for processing
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune