Skip to content

Commit 591c449

Browse files
committed
Add David Underhill's git-purge-from-history script from his blog
1 parent 03350e4 commit 591c449

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ git clone this repository, then add it to your `$PATH`. Nothing here actually re
110110
* git-outgoing - Michael Markert's [dotfiles](https://github.com/cofi/dotfiles)
111111
* git-promote - Trevor's [Improving My git Workflow](http://hoth.entp.com/2008/11/10/improving-my-git-workflow) blog post
112112
* git-publish - Michael Markert's [dotfiles](https://github.com/cofi/dotfiles)
113+
* git-purge-from-history - David Underhill’s [blog](http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/)
113114
* git-rank-contributors - William Morgan <wmorgan-git-wt-add@masanjin.net>
114115
* git-rebase-authors - Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles)
115116
* git-rel - Ryan Tomayko's [dotfiles](http://github.com/rtomayko/dotfiles)

git-purge-from-history

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -o errexit
3+
4+
# Author: David Underhill
5+
# Script to permanently delete files/folders from your git repository. To use
6+
# it, cd to your repository's root and then run the script with a list of paths
7+
# you want to delete, e.g., git-delete-history path1 path2
8+
#
9+
# retrieved from: http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/
10+
#
11+
12+
if [ $# -eq 0 ]; then
13+
exit 0are still
14+
fi
15+
16+
# make sure we're at the root of git repo
17+
if [ ! -d .git ]; then
18+
echo "Error: must run this script from the root of a git repository"
19+
exit 1
20+
fi
21+
22+
# remove all paths passed as arguments from the history of the repo
23+
files=$@
24+
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD
25+
26+
# remove the temporary history git-filter-branch otherwise leaves behind for a long time
27+
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune

0 commit comments

Comments
 (0)