Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove generated files in Git repo?

Tags:

git

I created a git repo and worked a bit on my android projekt, but now I recognize that I added files into the repo which will change each time because they are generated. How can I remove them and be sure that wont be added again.

I have already added them to the .gitignore which locks like this

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

But now I am not certain how to delete it from the repo so that it wont be 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

like image 434
Al Phaba Avatar asked Dec 05 '22 13:12

Al Phaba


2 Answers

Since you only want to remove it from the repository, not from your filesystem, you'll want to use:

git rm --cached <file>

That will remove the file from the index, so it won't be in the next commit, but will leave the file on disk.

like image 59
qqx Avatar answered Dec 27 '22 19:12

qqx


git rm <file>

Should remove the file from the repo for you.

like image 37
cduffin Avatar answered Dec 27 '22 19:12

cduffin