remove a file from GIT control

GitGithubGit Svn

Git Problem Overview


> Possible Duplicate:
> git - removing a file from source control (but not from the source)

I have a .classpath file which is currently in GIT repository.

After I pulled from remove repository(git pull origin master). How can I remove this file from GIT control, I mean NOT to delete this file from my computer but remove it from GIT version control. (Because this file is not needed for version control).

P.S.

I tried git rm <path-to>/.classpath , but then my whole project complains about wrong class path, why git rm delete my file instead of remove from version control ???

Git Solutions


Solution 1 - Git

Use git rm --cached to remove from the index but not the working tree.

After that, you should add .classpath to your .gitignore file, to prevent it from being committed again.

Solution 2 - Git

> why git rm delete my file instead of remove from version control ???

Because that's what it says it will do.

$ git help rm
NAME
       git-rm - Remove files from the working tree and from the index

SYNOPSIS
       git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet]
       [--] <file>...

DESCRIPTION
       Remove files from the index, or from the working tree and the index.
       ... When --cached is given,
       the staged content has to match either the tip of the branch or the
       file on disk, allowing the file to be removed from just the index.

OPTIONS
      ...

       --cached
           Use this option to unstage and remove paths only from the index.
           Working tree files, whether modified or not, will be left alone.

As Platinum Azure says, use git rm --cached to only remove it from source control, and use .gitignore to keep it out and stop it showing in git status.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLeem.finView Question on Stackoverflow
Solution 1 - GitPlatinum AzureView Answer on Stackoverflow
Solution 2 - GitUselessView Answer on Stackoverflow