git .gitignore 不忽略以前跟踪的文件

git .gitignore not ignoring previously tracked files

我有一个 Android 工作室项目(从 eclipse 导入)。在我导入到 Andorid studio 之后,我做了一个初始提交并忘记为 Android Studio 的结构添加新的 .gitignore 文件。

现在 git 不会忽略构建、.gradle 文件等

我试过了

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

技巧,但当我写 git status 时,所有文件都显示为已删除,在 github 中它们显示为已更改。

下面是我的。git忽略

.gradle
/local.properties
/.idea/workspace.xml
.DS_Store

# Created by http://gitignore.io

### Android ###
# 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

# Eclipse project files
.classpath
.project    

# Proguard folder generated by Eclipse
proguard/

# Proguard folder generated by Intellij
proguard_logs/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/

adt-bundle-windows-x86_64/

### Linux ###
.*
!.gitignore
!.git*
*~


### IntelliJ ###
*.iml
*.ipr
*.iws
.idea/

### Gradle ###
# Exclude Folder List #
.gradle/
build/

/*/out
/*/*/build
/*/*/production
*.iws
*.ipr
*~
*.swp

我仍然可以看到我的构建和 .gradle 文件夹等中的所有文件

有什么建议吗?

也许,您需要使用这种语法:

**/build

  1. git rm --cached "xxx"
  2. git commit -m ""
  3. git reset HEAD -- "xxx"
  4. git commit -m ""(更新回购协议)

git clean -xf 删除所有与 .gitignore 匹配的文件。