0

Please see this question, and my comment at the bottom of the question.

I have just cloned a repo in a Windows 10 OS which I developed in Linux, and git won't let me check to a branch because elements in it have paths which are illegal in Windows. To work around this I have checked out the branch concerned in WSL.

But what I want to do is delete all elements matching a pattern in all commits in a given branch (or indeed throughout the entire repo). Is there any way to do that?

This is the error I got in W10 (i.e. before going into WSL):

D:\My documents\doc_indexer>git checkout br_2022_01_16 error: invalid path 'D:\temp\logging/doc_indexer/.__rotator_fh.lock' error: invalid path 'D:\temp\logging/doc_indexer/rotator_fh.log.1' 

These paths are illegal in Windows not least because they contain a ":". These two files are not showing in WSL as part of the commit on the checked out branch ... and are therefore in older commits in this branch.

How might I weed them out and destroy them? If this is very hard or impossible, is there something else I might do so I can check out this branch in W10 "normal"?

Answers to comment questions

git ls-tree -r br_2022_01_16 : yes, those blobs are listed there...

git rev-parse --show-toplevel : this shows the root directory, i.e. the one containing dir ".git".

3
  • Do they show up if you run git ls-tree -r br_2022_01_16? Commented Jan 28, 2022 at 21:20
  • where is the root of your repository located ? git rev-parse --show-toplevel Commented Jan 28, 2022 at 21:34
  • see answers. does their presence in the ls-tree command mean something about their deletability? Commented Jan 29, 2022 at 17:02

1 Answer 1

1

You can use git filter-branch to delete files from all commits. This operation can be destructive, it is a good idea to make a backup of your repo before running it.

git filter-branch --index-filter 'git rm --cached --ignore-unmatch files to delete' --all 

There's also git filter-repo which is a newer alternative to filter-branch:

git filter-repo --path files --path to --path delete --invert-paths 

Depending on your exact use case, --path-regex, --path-glob, or --paths-from-file might give you better user experience.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.