从GIT控制删除文件
问题描述:
可能重复:
git - removing a file from source control (but not from the source)从GIT控制删除文件
我有一个.classpath
文件这是目前在Git仓库。
当我从删除存储库(git pull origin master
)拉。我如何从GIT控件中删除此文件,我的意思是NOT to delete
这个文件来自我的电脑,但是将它从GIT版本控制中删除。 (因为这个文件不需要版本控制)。
P.S.
我试过git rm <path-to>/.classpath
,但后来我的整个项目抱怨错误的类路径,为什么git rm删除我的文件,而不是从版本控制中删除?
答
使用git rm --cached
从索引中删除而不是工作树。
之后,您应该将.classpath
添加到.gitignore文件中,以防止它再次被提交。
答
为什么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.
铂Azure的说,用git rm --cached
只从源代码控制删除它,并使用.gitignore
让出来,并阻止它显示git status
。
如何添加到.gitignore,你可以更具体吗? – 2012-02-15 16:07:18
'git help ignore'或搜索网页 - 明显发布任何gitignore问题,试过一次 – Useless 2012-02-15 16:10:28
在目录顶部,创建一个名为“.gitignore”的文件,并将'.classpath'放入其中。您还可以使用通配符忽略匹配某种模式的文件(例如,* .class'忽略所有已编译的Java类)。你也许可以在子目录中执行.gitignores(它只适用于项目的那部分),但我忘记了。见http://linux.die.net/man/5/gitignore – 2012-02-15 16:10:45