Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove git sensitive datas
#!/usr/bin/ruby
#
# Remove history of files wich contains passwords and commit the last version of the file
# http://help.github.com/remove-sensitive-data/
#
# How to use ?
# 1) Clone your repo
# 2) copy this file at the root of the repo
# 3) update glob_to_rewrite
# 4) run ruby git_rewrite.rb
# 5) Rebase all your branches
#
#!/usr/bin/ruby
#
require 'find'
master_branch = 'master'
`git co #{master_branch}`
branch = `git branch | grep ^*`.strip.gsub('* ','')
#Symfony1 potentially sensitive files
files_to_rewrite = %w()
glob_to_rewrite = %w(config/*.yml* config/*.ini apps/*/config/*.yml plugins/*Plugin/config/*.yml)
glob_to_rewrite.each do |glob|
find = %w()
puts "Search for #{glob}"
Dir.glob(glob) do |path|
if (File.file?(path))
find.push(path)
`cp #{path} #{path}.dump`
end
end
`git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch #{glob}'`
find.each do |filename|
`cp #{filename}.dump #{filename}`
`rm #{filename}.dump`
end
`git gc --aggressive --prune=now`
`git push origin #{branch} --force`
`git add #{glob}`
`git ci -m"Restore anonymised file #{glob}"`
`git push origin #{branch}`
end
files_to_rewrite.each do |filename|
puts ">>Rewrite #{filename}"
`git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch #{filename}'`
`cp #{filename}.dump #{filename}`
`rm #{filename}.dump`
`git gc --aggressive --prune=now`
`git push origin #{branch} --force`
`git add #{filename}`
`git ci -m"Restore anonymised file #{filename}"`
`git push origin #{branch}`
end
puts "Now run git rebase for all your dist branches"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.