无法使用Git从跟踪中删除文件

时间:2014-09-24 13:07:08

标签: git

我在跟踪文件时遇到了一个奇怪的问题。 我有一个跟踪文件index.css。然后我将其添加到.gitignore。然后我运行以下命令并获得输出:

$ git rm --cached build/development/css/index.css
rm 'build/development/css/index.css'

运行git status会提供以下内容:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    build/development/css/index.css

当尝试提交更改时,我收到以下错误:

Error:On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
 during executing git commit --only -F C:\Users\dtv\AppData\Local\Temp\git-commit-msg-7154374096157077481.txt -- build/development/css/index.css

如果我尝试将更改提交到index.css以及其他更改,则提交会毫无错误地进行。但仍会检测到对文件的更改。我做错了什么?

3 个答案:

答案 0 :(得分:1)

问题是--only的{​​{1}}选项。来自git commit联机帮助页:

  

仅从命令行中指定的路径进行提交,   无视到目前为止上演的任何内容。

尝试提交该文件,忽略之前的git-commit命令。

答案 1 :(得分:1)

  • 根据我的观察,如果我们使用这个git rm --cached filename命令,它只会在那个时间忽略。
  • 如果您在 .gitignore 中添加该文件,git将永久忽略(取消)该文件。在向 .gitignore 添加文件名或路径后,我们必须执行以下命令以从下次开始取消跟踪这些文件

    首先提交任何未完成的代码更改,然后运行以下命令

    git rm -r --cached . - &gt;这将从索引(暂存区域)中删除所有已更改的文件

    git add .

    git commit -m ".gitignore is now working" - &gt;提交更改

答案 2 :(得分:1)

你试过了吗?

git update-index --assume-unchanged path_to_file

这将在索引中标记文件,git将停止跟踪文件以进行任何修改。结合在 .gitignore 中添加此文件,它将在使用时停止将其显示为已修改

git status

您还可以查看update-index

的文档
相关问题