【问题标题】:cannot add folder to gitignore file [duplicate]无法将文件夹添加到 gitignore 文件 [重复]
【发布时间】:2013-09-03 14:12:11
【问题描述】:

我的.gitignore 文件如下:

$ cat .gitignore
Index/
Index/LOG

我添加了.gitignore 文件来回购、提交甚至推送。但是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:   Index/LOG
#

那么如何永远从 git 存储库中排除整个 Index 文件夹?

【问题讨论】:

  • 如果添加了Index/LOG,则应将其删除。

标签: git


【解决方案1】:

Git 不会忽略跟踪的文件。您需要从存储库中删除该文件,然后它才会被忽略:

$ git rm -r Index
$ git commit -m "Deleting 'Index' folder."

这将删除文件。如果您只想从索引中删除它们,请使用 --cached:

$ git rm -r --cached Index

这会将所有文件保留在文件系统中,并且只会从 git 中删除它们。

【讨论】:

    【解决方案2】:

    要排除 Index 文件夹,请将其删除并提交更改。概述如下:

    就是这么简单。如果你只想更新索引告诉 git 即使它改变了也没有改变,使用update-index commmand:

    【讨论】:

      猜你喜欢
      • 2018-05-25
      • 2014-04-30
      • 1970-01-01
      • 2013-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      • 2016-10-31
      相关资源
      最近更新 更多