git .gitignore not ignoring previously tracked files

微笑、不失礼 提交于 2019-12-11 10:15:44

问题


I have an Android studio project (imported from eclipse). After I did the import to Andorid studio I did an initial commit and forgot to add the new .gitignore file for Android Studio's structure.

Now git won't ignore the build, .gradle files etc.

I have tried the

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

trick but still when I write git status all files appear as deleted and in github they appear as changed.

Below is my .gitignore

.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

I can still see all files in my build and .gradle folders etc.

Any suggestions?


回答1:


  1. git rm --cached "xxx"
  2. git commit -m ""
  3. git reset HEAD -- "xxx"
  4. git commit -m "" (to update repo)



回答2:


git clean -xf removes all files that matches .gitignore.




回答3:


Perhaps, you need to use this syntax:

**/build



来源:https://stackoverflow.com/questions/33713591/git-gitignore-not-ignoring-previously-tracked-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!