Search code examples
gitjar

Error: Unable to access jarfile bfg.jar - BFG


So I have mistakenly committed my secrets.yml in previous commits (yikes!!) and I want to clean my git commit history of it. It seems the fasted simplest way is to use BFG. I have downloaded the jar file and installed the Java is requires, and I have created a mirror of my repo - but when I run the command as per the docs:

java -jar bfg.jar --delete-files secrets.yml my-repo.git

I get the error Unable to access jarfile bfg.jar

The docs are plenty pretty, but doesn't specify if there is something I should have done to install this or get it running, or linked to my mirror repo, and I am plenty confused. I watched a youtube tutorial that says I should create a symbolic link using a command like;

ln -s ~/bfg-1.11.6.jar /usr/local/bin/bfg

to run the bfg, except I am uncertain what the second part of that command is referring to( /usr/local/bin/bfg ) or where it should be pointing in my case, as that does not work for me as-is. I have the jar file saved in my user root directory. Do I need to move it? How do I run BFG on my mirror repo, and should I be inside my mirror app's directory when I run it?Or do I run it from outside of the app?


Solution

  • 2015: From the documentation, it should be:

    java -jar bfg.jar <options> yourrepo
    

    Try and use the full path of the jar if you have an error like "Unable to access jarfile bfg.jar": /home/user/path/to/bfg.jar.

    If the jars are configured to be run with java, then /usr/local/bin/bfg would be the path of the symlink referencing the right bfg jar.

    The alternative is described in "Remove sensitive data"

    git filter-branch --force --index-filter \
    'git rm --cached --ignore-unmatch Rakefile' \
    --prune-empty --tag-name-filter cat -- --all
    

    Or (update Nov. 2017), as commented by JeremyDouglass,

    If you download the latest (e.g. from 1.12.16, the bfg-1.12.6.jar) and you only want to use standard commands in a local staging directory only (no path, no symlink), then you can simply rename the jar:

    mv bfg-1.12.16.jar bfg.jar 
    java -jar bfg.jar --delete-files bad.txt repo.git
    

    2019-2020: more recently, you would now use You should use git filter-repo (that I mentioned here).

    Install it first. (python3 -m pip install --user git-filter-repo)

    Then, using a path-based filter:

    git filter-repo --path secrets.yml --invert-paths HEAD
    

    HEAD means it will change only your current branch commits.
    Remove HEAD and it will go over all your commits in all your branches.