How to use git filter-repo In GIT

Git filter-repo is a tool used to rewrite Git repository history by applying various filters. It can be used to remove files, change file paths, modify commit messages, and more. This can be useful for cleaning up repository history or preparing a repository for public release.

Install git filter-repo:

pip install git-filter-repo

Command to Remove the File:

git filter-repo --path path/to/gfg.jpg --invert-paths

Explanation of the Command:

  • git filter-repo: The command to invoke the tool.
  • –path path/to/gfg.jpg: Specifies the path to the file you want to remove.
  • –invert-paths: Removes the specified paths from history instead of keeping them.

Successful Removal Output:

If the file was successfully removed, you’ll see output similar to:

Parsed 50 commits
New history written in 2.33 seconds;
now repacking/cleaning your repo...
Repacking your repo and cleaning out old unneeded objects
Enumerating objects: 36, done.
Counting objects: 100% (36/36), done.
Delta compression using up to 4 threads
Compressing objects: 100% (18/18), done.
Writing objects: 100% (36/36), done.
Total 36 (delta 10), reused 0 (delta 0)
Ref 'refs/heads/master' was rewritten

Force Pushing to Remotes:

git push origin --force --all

How to Remove a Large File from Commit History in Git?

Simply removing a large file through a commit won’t truly eliminate it. Git stores all versions of files in its history, even deleted ones, to allow for easy recovery. This can lead to wasted disk space.

We will discuss the various approaches for removing a large file from the commit history in Git:

Table of Content

  • Using git filter-branch
  • Using git filter-repo
  • Using BFG Repo-Cleaner

Similar Reads

Using git filter-branch

Let’s say you committed a large file, like a 15MB photo named gfg.jpg, in a previous commit. To completely erase it from Git’s history, use the following command in your project directory:...

Using git filter-repo

Git filter-repo is a tool used to rewrite Git repository history by applying various filters. It can be used to remove files, change file paths, modify commit messages, and more. This can be useful for cleaning up repository history or preparing a repository for public release....

Using BFG Repo-Cleaner

The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history:...

Summary

To remove a large file from Git history, you can use:...

Contact Us