Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Files completely from git repository along with its history

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?

like image 581
Yosh Iku3 Avatar asked Jan 31 '16 15:01

Yosh Iku3


People also ask

How do I remove files from my entire git history?

The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

How do I remove something from a git repository?

The "rm" command helps you to remove files from a Git repository. It allows you to not only delete a file from the repository, but also - if you wish - from the filesystem. Deleting a file from the filesystem can of course easily be done in many other applications, e.g. a text editor, IDE or file browser.

Does git rm remove history?

No, git rm will only remove the file from the working directory and add that removal into the index. So only future commits are affected. All previous commits stay the same and the history will actually show when you removed the file from the repository.


2 Answers

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.

like image 68
Gupta Avatar answered Oct 15 '22 23:10

Gupta


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).

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.

like image 36
geek-merlin Avatar answered Oct 15 '22 21:10

geek-merlin