How to delete generated files in git repo?

I created a git repository and worked a bit on my Android project, but now I understand that I have added files to the repo that will change every time because they are generated. How can I delete them and make sure that they will not be added again.

I already added them to .gitignore, which blocks as follows

bin/classes/** gen/** bin/PDiXUploader.apk bin/classes.dex bin/resources.ap_ gen/de/srs/android/pdixuploader/R.java 

But now I'm not sure how to remove it from the repo so that it is not under version control.

This is my git status log

 $ 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: bin/PDiXUploader.apk # modified: bin/classes.dex # modified: bin/resources.ap_ # modified: gen/de/srs/android/pdixuploader/R.java # modified: res/layout/activity_instance_selection.xml # modified: res/layout/activity_main.xml # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # res/values/dimens.xml no changes added to commit (use "git add" and/or "git commit -a") 

thanks

+4
source share
3 answers
 git rm <file> 

Must remove the file from the repo for you.

+3
source

Since you want to remove it from the repository, and not from your file system, you want to use:

 git rm --cached <file> 

This will remove the file from the index, so it will not be in the next commit, but will leave the file on disk.

+9
source

git rm is the answer if you want the file to go forward.

If you want the generated file to never be in the repo, you need to take a look at git filter-branch , the first example in particular.

+3
source

Source: https://habr.com/ru/post/1448004/


All Articles