【问题标题】:.gitignore does not ignore one folder.gitignore 不会忽略一个文件夹
【发布时间】:2014-07-21 21:19:05
【问题描述】:

我的 .gitignore 中有以下内容:

#built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Windows thumbnail db
Thumbs.db
# OSX files
.DS_Store
# Eclipse project files
.classpath
.project
# Android Studio
.idea
build/
cache.properties.lock
.idea/workspace.xml
*.iws
.gradle/
**/.gradle/

但是,每当我对我的应用进行更改时,git 都会在提交中包含 .gradle/1.12/taskArtifacts/cache.properties.lock 之类的文件。

这里有什么问题?为什么它适用于文件夹build/ 而不适用于.gradle/

【问题讨论】:

  • 这很可能是由于该文件夹中的某些文件已经在 git 中被跟踪。尝试运行 git rm --cached .gradle 并提交更改。
  • @BroiSatse 谢谢,成功了!似乎我认为 .gitignore 会做一些它不会做的事情。
  • 它确实告诉 git 在更新索引时忽略新文件。如果索引已经跟踪该文件,它将被标记为已修改,因为它不再是新的。

标签: git gitignore


【解决方案1】:

Git 可能已经在跟踪这些文件。在终端中运行以下命令对 .gradle.idea 文件都有效:

git rm --cached .gradle -r

【讨论】:

  • 谢谢!这解决并删除了这些文件,以及我到底需要什么
【解决方案2】:

这对于不包含的点(。)很常见,将其添加到.gitignore

.*
!/.gitignore

【讨论】:

    【解决方案3】:

    这可能是因为 git 已经在跟踪这些文件。停止跟踪该文件,然后提交并推送。

    在源代码树中:

    • 右键单击文件并选择停止跟踪
    • 提交更改
    • 推到原点

    【讨论】:

    • 请补充:在Visual Studio Code,git tab。
    【解决方案4】:

    我也遇到了同样的问题,希望对你有帮助:

    • 打开终端并转到根文件夹
    • 执行:git rm -rf .gradle/
    • 然后执行这个:git rm --cached .gradle -r
    • 提交更改并再次同步

    【讨论】:

      猜你喜欢
      • 2021-09-29
      • 2021-09-24
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 2018-05-02
      • 1970-01-01
      • 2018-01-12
      相关资源
      最近更新 更多