从GIT控件中删除文件

Lee*_*fin 46 git github git-svn

可能重复:
git - 从源代码管理中删除文件(但不是从源代码中删除)

我有一个.classpath目前在GIT存储库中的文件.

我从remove repository(git pull origin master)中删除后.如何从GIT控件中删除此文件,我的意思是NOT to delete来自我的计算机的此文件,将其从GIT版本控制中删除.(因为版本控制不需要此文件).

PS

我试过git rm <path-to>/.classpath,但是然后我的整个项目抱怨错误的类路径,为什么git rm删除我的文件而不是从版本控制中删除?

Pla*_*ure 97

用于git rm --cached从索引中删除但不从工作树中删除.

之后,您应该添加.classpath到.gitignore文件,以防止再次提交.

  • 在目录顶部,创建一个名为“.gitignore”的文件并将“.classpath”放入其中。您还可以使用通配符来忽略与特定模式匹配的文件(例如,“*.class”来忽略所有已编译的 Java 类)。您也许还可以在子目录中执行 .gitignores (然后仅适用于项目的该部分),但我忘记了。请参阅http://linux.die.net/man/5/gitignore (2认同)
  • 是的,这适用于像`.classpath`这样的单个文件。我还建议提交 `.gitignore` 文件,以便其他开发人员使用它,并且不会意外提交 `.classpath`。 (2认同)

Use*_*ess 15

为什么git rm删除我的文件而不是从版本控制中删除???

因为这就是它所说的.

$ 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.
Run Code Online (Sandbox Code Playgroud)

正如Platinum Azure所说,git rm --cached只使用它从源代码控制中删除它,并用.gitignore它来阻止它并停止显示git status.