10

Im trying to purge a projects bin directory from Git history. I have already added 'bin' to .gitignore and run $git rm --cached -r bin successfully. Now I have tried using the command as recommended in the GitHub help pages to purge the history:

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

But this results in errors:

Rewrite <hash> (1/164) fatal: not removing 'bin' recursively without -r
index filter failed: git rm --cached --ignore-unmatch bin
rm: cannot remove 'c:/pathToMyLocalRepo/.git-rewrite/revs': Permission denied
rm: cannot remove directory 'c:/pathToMyLocalRepo/.git-rewrite': Directory not empty

There's no other programs holding /revs open. /revs does not exist in the specified path and .git-rewrite is empty.

I am not sure where exactly I should add the -r? Is the command incorrect otherwise?

I do, of course, need to keep bin itself in the local local repo as this is my working dir.

Thanks

Toby
  • 9,696
  • 16
  • 68
  • 132

2 Answers2

6

Okay so all I needed to do was add the -r to the rm command part (as below). I guess this is because bin is a directory rather than a file, so it must be removed recursively as otherwise the files it contains (or the information about them) would be orphaned.

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

I followed this with the below to push the changes to the remote repo on github

$ git push origin master --force
Toby
  • 9,696
  • 16
  • 68
  • 132
2

The only place it makes sense is after the git rm. I have not tried it myself but I think that should work?

$ git filter-branch --force --index-filter \
  'git rm -r --cached --ignore-unmatch bin' \
  --prune-empty --tag-name-filter cat -- --all
Honril Awmos
  • 192
  • 3
  • LOL posted just as I tried it anyway! had a backup of the files so figured I would just go ahead and throw it in where I though best and restart the repo if something went wrong. Cheers anyhoo – Toby Sep 11 '13 at 17:11
  • Just a side note, I had to use `"` in place of `'` as I was getting an error (using `cmd` on Windows machine) – Eric Mar 02 '20 at 13:37