Quantcast
Channel: Unix Superhero » cli
Viewing all articles
Browse latest Browse all 6

Git Tip: Remove a file from your entire git repo

$
0
0

tl;dr

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch path/to/file' --prune-empty --tag-name-filter cat -- --all

Why Do This?

Here are a few reasons why you might want to do this:

  1. Someone checked in a file containing passwords or other sensitive info
  2. Someone checked in a large file like a PSD

Even if you have a later commit that deletes this file, it is still in your git index and it is still accessible.  The above command will search for that file in every commit in all tags and remove it.

Caveats

Every sha, or nearly every sha, in your git log will be rehashed.  Meaning, pushing to a remote repo will probably require a force push.

Other Uses

The git command name is filter-branch, not remove file.  This command allows you to pass it various commands to filter your index and tags through.  If there is a different command that you want to run on all commits put it in the quotes after –index-filter.

I don’t know anything else about this command.  Normally I would read the man page, because I don’t like using something without understanding it.  But, I’ll do that later.



Viewing all articles
Browse latest Browse all 6

Trending Articles