Remove an Existing File from a Git Repo

Just to give the full answer all at once:

  1. from klemens: You need to add the file to your .gitignore file somewhere above the undesired file in the repo. i.e.

    $ cd
    $ cat >> .gitignore
    development.log
    C-d

  2. from m. narebski: You then need to remove the file from the repo by executing “git rm --cached <file> and then committing this removal”

If you were also hoping to make the repo look as if it had never tracked that file, that is much more complicated and highly discouraged as it not only creates brand new commits for every single commit in your history, thus destroying interoperability in a nasty way between other people who have cloned your repo, but it also leaves every one of those commits untested (assuming you test your commits before making them).

With that caveat in mind, the tool you’re looking for if that’s your goal is filter-branch. The first example does exactly what I’m describing.

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.