Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing history from git - git command fails

Tags:

git

github

purge

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

like image 817
Toby Avatar asked Sep 11 '13 16:09

Toby


People also ask

How to delete history from git?

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. The git filter-repo tool and the BFG Repo-Cleaner rewrite your repository's history, which changes the SHAs for existing commits that you alter and any dependent commits.

How to remove files in git?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.

How to remove a file from git index?

If you want to completely remove the file from the index, you will have to use the “git rm” command with the “–cached” option. In order to make sure that your file was correctly removed from the staging area, use the “git ls-files” command to list files that belong to the index.


1 Answers

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
like image 138
Honril Awmos Avatar answered Oct 14 '22 04:10

Honril Awmos