Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove an Existing File from a Git Repo

Tags:

git

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.


To stop tracking the file, simply use git rm --cached <filename>.

But as pointed out by the others here, adding the file to .gitignore might prevent you from accidentally adding it again later.


add the gitignore file.

see http://git-scm.com/docs/gitignore