Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing files from git history - bad revision error

Tags:

git

I am following the instructions on Github (https://help.github.com/articles/remove-sensitive-data/) to tidy up a messy repository. I have successfully cleared out all the .csv files using

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

And now need to remove all the .docx files. However, when I use exactly the same command with *.docx instead, I get an error saying: fatal: bad revision ' --prune-empty'

I pushed to the origin on github, and cloned a fresh copy before doing this second lot of updates. I'm not sure what I'm doing wrong/differently that is causing this error. Any help greatly appreciated :)

like image 380
Froom2 Avatar asked Sep 22 '15 10:09

Froom2


People also ask

Can I remove a file from git history?

If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history. To entirely remove unwanted files from a repository's history you can use either the git filter-repo tool or the BFG Repo-Cleaner open source tool.

How do I purge files in git?

The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.


2 Answers

Git should run from either cmd.exe or bash.

The problem is the use of ' in your command. Windows only uses ". The command you are looking for is:

git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch *.csv" \ --prune-empty --tag-name-filter cat -- --all 
like image 135
c z Avatar answered Sep 30 '22 13:09

c z


Solved... I took out the space after the backslash which I'd been putting in before the --prune-empty part, and it works as expected now! No idea why it works though....

like image 43
Froom2 Avatar answered Sep 30 '22 14:09

Froom2