How to ignore a file that is already installed?

Previously, my .gitignore file was as follows:

 ... config/database.yml .DS_Store 

Later I created the app_config.yml file in the configuration directory and committed it.

Now I realized that I do not need the app_config.yml file in the git repository. And I changed the .gitignore file:

 ... config/app_config.yml config/database.yml .DS_Store 

Now that I app_config.yml , this app_config.yml file is still in my repo. I want to delete this file from my repo. How can i do this?

+23
git gitignore
Mar 09 '09 at 11:52
source share
1 answer

As mentioned in " ignoring does not delete the file "
(The following quote is a great article from Nick Caranto ,
on my git blog, the finished "learn git one commit at a time"):

When you tell git to ignore files, it is going to stop viewing the changes for that file and nothing more.
This means that the story will still remember the file and have it .

If you want to delete the file from the repository, but save it in your working directory, just use:

 git rm --cached <file> 

However, this will still save the file in history.

If you really want to remove it from the story, you really have two options:

  • rewrite your repositories, or
  • Start.

Both options really suck, and this is for a good reason: git is trying not to lose your data.
As with rebooting, git makes you think of these options as they are destructive operations.

If you really want to delete a file from history, git filter-branch is the hand saw you are looking for.
Definitely read its manpage before using it, as it will literally rewrite your projects. This is really a great tool for some actions and can do all kinds of things, such as completely deleting authors that require you to move the project root folder. The command to delete a file from all revisions:

 git filter-branch --index-filter 'git rm --cached <file>' HEAD 

This action can be useful when you need to blow out confidential or confidential information that could be placed in your repository.

+41
Mar 09 '09 at 12:04
source share



All Articles