【问题标题】:git add/commit deleting and not just ignoring .gitignore ignored filegit add/commit 删除而不仅仅是忽略 .gitignore 被忽略的文件
【发布时间】:2012-04-02 14:34:00
【问题描述】:

我已经尝试过 Stackoverflow 上一个关于如何忽略文件的问题的建议:Ignore files that have already been committed to a Git repository

建议:

git rm -r --cached .

我正在使用的命令:

git rm -r --cached application/config/config.php
//i only want to ignore this one file

不幸的是,当我执行 git add.git commit 时,我的 config.php 已从存储库中删除,而不仅仅是被忽略。

我的根目录中有一个 .gitignore 文件,它包含以下列表项:

application/config/config.php

也许有人能帮我理解为什么这个 config.php 文件被删除而没有被忽略?

这是我的 git 状态显示的内容:

$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .gitignore
#   modified:   application/config/config.php
#
no changes added to commit (use "git add" and/or "git commit -a")

谢谢你,

提姆

【问题讨论】:

  • 在您执行add .commit 之前,git status 报告是什么?
  • 嗨阿里,请看上面修改后的问题,谢谢!
  • 您已修改文件。试试git checkout -- application/config/config.php
  • 嗨 mschonaker,感谢您的意见,下面关于使用 git update-index --assume-unchanged &lt;filename&gt; 的答案对我有用,

标签: git github gitignore


【解决方案1】:

它正在从存储库中删除,因为您已将其删除。 git rm 是删除文件,--cached 将其保留在您的工作目录中。

如果您想这样做,您可以使用git update-index --assume-unchanged &lt;filename&gt;,这样它就不会注意到文件的更改,而是将旧版本留在您的存储库中。进一步阅读:http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html

【讨论】:

  • 嗨,丹,效果很好!我怀疑rm 不是正确的命令,但我不知道git update-index...。谢谢!
猜你喜欢
  • 2012-07-12
  • 1970-01-01
  • 2011-09-30
  • 2020-10-13
  • 1970-01-01
  • 2017-09-19
  • 2015-11-30
  • 2015-11-30
  • 1970-01-01
相关资源
最近更新 更多