Reputation: 35
I need to completely remove a folder and all of its files from the history of a git repository and I need to ignore any future changes to that folder.
Using Git-Bash, I have already tried a filter-branch command with a git remove command nested within it. Below is my command.
git filter-branch --force --index-filter \ "git rm -rf --cached --ignore-
unmatch C:\Foldername" \--prune-empty --tag-name-filter cat -- --all
I expected the folder to be removed from all versions of the repository, but I received an error message instead:
fatal: bad revision 'git rm -rf --cached --ignore-unmatch C:\Foldername'
I then tried the command:
git rm -rf --cached --ignore-unmatch "C:\Foldername"
which worked by itself. However this does not accomplish the task of removing the folder from the entire history of the repository.
Update: I just ran the command removing the space before "git. As shown below.
git filter-branch --force --index-filter \ "git rm -rf --cached --ignore-
unmatch C:\Foldername" \--prune-empty --tag-name-filter cat -- --all
I now get this message:
fatal: C:Foldername: 'C:Foldername' is outside repository
index filter failed: git rm -rf --cached --ignore-unmatch C:\Foldername
rm: cannot remove 'C:/.git-rewrite': Directory not empty
Upvotes: 0
Views: 4399
Reputation: 487755
You have a lot of weirdly placed backslashes, as if you used cut-and-paste on what was originally a multi-line command example like this:
echo I \
am a \
multi-line \
example
but turned it into a single line without removing the backslashes:
echo I \ am a \ multi-line \ example
Try running both—one with the newlines, so that each backslash is the very last character of an actual complete line, and one without—and compare the output:
$ echo I \
> am a \
> multi-line \
> example
I am a multi-line example
$ echo I \ am a \ multi-line \ example
I am a multi-line example
Can you see the difference between the two outputs? It has to do with white space, and is hard to tell sometimes. I have a second trick I like to use, based on the fact that the wc
command prints its arguments in error messages, one per line:
$ wc I \ am a \ multi-line \ example
wc: I: No such file or directory
wc: ' am': No such file or directory
wc: a: No such file or directory
wc: ' multi-line': No such file or directory
wc: ' example': No such file or directory
0 0 0 total
Note that the files wc
tried to open were named I
, ' am'
—a file name with a leading space—and so on.
In this case, git filter-branch
thought that the --index-filter
it should use was , which is a command that won't do much (but is actually valid here). Then the next thing after that was a commit-selector, but it did not work as a commit-selector. That's where your error came from.
In this case, since you're not using multiple lines, you should just remove all the backslashes. That will give you a different problem, because git rm -rf --cached
should be given the relative file names, not a full path name.
Upvotes: 1