Skip to content

Instantly share code, notes, and snippets.

@paneru-rajan
Last active July 7, 2018 06:54
Show Gist options
  • Save paneru-rajan/fa6cf2232b5fc058d9861a5e34ffcea3 to your computer and use it in GitHub Desktop.
Save paneru-rajan/fa6cf2232b5fc058d9861a5e34ffcea3 to your computer and use it in GitHub Desktop.
[Git Remove one file form entire repository and history] When some file mistakenly added on git, and after many commits you come to realize that the file was not supposed to be there #git #remove-file #bitbucket #github

Remove file form git history and current head (Remove Completely)

Note: I have tested this on my bitbucket dummy repo

I have mistakely added password on README.md and after many commits, I was reminded what I have done. So the below stuff is to correct my fault

Download from here

wget http://repo1.maven.org/maven2/com/madgag/bfg/1.13.0/bfg-1.13.0.jar

Otherwise, go to this page and download it from there

Clone a fresh copy of your repo, using the --mirror flag:

git clone --mirror git://example.com/some-repo.git

Run the BFG to clean your repository up

Note: I want to delete completely so i have added --no-blob-protection

java -jar ~/Downloads/bfg-1.13.0.jar --delete-files <File_name_here> --no-blob-protection some-repo.git    

And do this

cd some-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push

Refrences

  1. BFG Repo-Cleaner
  2. Bitbucket Support
  3. Github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment