Skip to content

Instantly share code, notes, and snippets.

@cookrn
Created Mar 14, 2012
Embed
What would you like to do?
Ruby Script to Remove File FOREVER From Git Repo
# Make a backup first!
# Place at the root of the desired git repo
# Run w/ commit SHA as first argument e.g. ruby fix.rb 57415b9c864e4128dca805b4a8ad7b7e59281ac6
#
# All files in your list will be forever removed from the filesystem and git repo from given
# commit up to HEAD
files = %w(
you.r
list.of
fil.es
)
commit = ARGV[ 0 ]
command = "git filter-branch --index-filter 'git rm --cached --ignore-unmatch #{ files.join " " }' #{ commit }..HEAD"
puts command
# Uncomment the line below to actually run the command
# system command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment