从 GIT 控制中删除文件

发布于 2025-01-05 09:48:51 字数 576 浏览 0 评论 0原文

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

我有一个 .classpath 文件,当前位于 GIT 存储库中。

当我从删除存储库中拉出后(git pull origin master)。我怎样才能从 GIT 控制中删除这个文件,我的意思是不删除这个文件从我的计算机但是从 GIT 版本控制中删除它。 (因为版本控制不需要这个文件)。

PS

我尝试了 git rm/.classpath ,但后来我的整个项目抱怨类路径错误,为什么 git rm 删除我的文件而不是从中删除版本控制???

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 ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

属性 2025-01-12 09:48:51

使用 git rm --cached 从索引中删除,但不从工作树中删除。

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

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.

素衣风尘叹 2025-01-12 09:48:51

为什么 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.

正如 Platinum Azure 所说,使用 git rm --cached 仅将其从源代码管理中删除,并使用 .gitignore 将其保留并停止在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文