Remove Files completely from git repository along with its history
Asked Answered
J

4

105

I have uploaded a font file that I don't have the rights to distribute to git hub several updates ago.

I have a relatively inactive repository and I have the ability to notify all of my members if necessary. I've tried several of the solutions. I need to delete a file in my directory called Resources\Video\%font%.ttf where %font% is the name of the plain, italicized and bold versions of the font. What commands do I use?

Jaeger answered 31/1, 2016 at 15:31 Comment(0)
P
153

In that case you could to use Git Filter Branch command with --tree-filter option.

syntax is git filter-branch --tree-filter <command> ...

git filter-branch --tree-filter 'rm -f Resources\Video\%font%.ttf' -- --all

Edit Updated

Note that git filter-branch --index-filter is much faster than --tree-filter

git filter-branch --index-filter 'rm -f Resources\Video\%font%.ttf' -- --all

In windows had to use / instead of \.


Explanation about the command:

< command > Specify any shell command.

--tree-filter:Git will check each commit out into working directory, run your command, and re-commit.

--index-filter: Git updates git history and not the working directory.

--all: Filter all commits in all branches.

Note: Kindly check the path for your file as I'm not sure for the file path

Hope this help you.

Purpura answered 31/1, 2016 at 15:49 Comment(0)
S
64

According to the official git docs, using git filter-branch is strongly discouraged, and the recommended approach is to use the contributed git-filter-repo command.

Install it (via package, or with package python3-pip, do a pip install: pip install git-filter-repo).

The command to exorcise filename is then:

git filter-repo --invert-paths --path filename

The --invert-paths option indicates to exclude, not include the following paths.

Shapiro answered 24/2, 2021 at 22:53 Comment(0)
K
24

git filter-branch --index-filter 'git rm --cached --ignore-unmatch Resources\Video\%font%.ttf' HEAD can be much (up to 100x) faster than --tree-filter because it only updates git history and not the working directory.

ref: What is the difference between "--tree-filter" and "--index-filter" in the "git filter-branch"?
ref: https://git-scm.com/docs/git-filter-branch

Kokaras answered 24/12, 2019 at 4:58 Comment(0)
C
0

Take backup

Inside Working Directory
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch Resources\Video\%font%.ttf' --prune-empty --tag--name-filter cat -- --all 
git push origin --all --force 
Inside Bare Repo
git gc --prune=now
Chafe answered 1/10, 2023 at 7:12 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Goldstone

© 2022 - 2024 — McMap. All rights reserved.