Skip to content

Instantly share code, notes, and snippets.

@ayr-ton
Created May 22, 2018 21:05
Show Gist options
  • Save ayr-ton/a2b31e9d32d35b8b5305fdd026ee5173 to your computer and use it in GitHub Desktop.
Save ayr-ton/a2b31e9d32d35b8b5305fdd026ee5173 to your computer and use it in GitHub Desktop.
Completely remove a file from a git repository history
#!/usr/bin/env bash
# Completely remove a file from a git repository history
#
# Copyleft 2018 by Ayrton Araujo <root _a_t_ ayr-ton _d_o_t_ net>
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage:
# git-forget-blob file_to_forget
# If you move this script to somewhere inside $PATH you could use the script like:
# git forget-blob file_to_forget
#
# Notes:
# It rewrites history, therefore will change commit references and delete tags
function git-forget-blob()
{
git filter-branch --tree-filter 'rm -f "$1"' HEAD
}
# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA
git-forget-blob $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment