Skip to content

Instantly share code, notes, and snippets.

@cookrn
Created March 14, 2012 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cookrn/2037360 to your computer and use it in GitHub Desktop.
Save cookrn/2037360 to your computer and use it in GitHub Desktop.
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