Al Phaba
Al Phaba

Reputation: 6785

How to remove generated files in Git repo?

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

Upvotes: 4

Views: 3536

Answers (3)

siride
siride

Reputation: 209985

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

If you want the generated file never to have been in the repo, you'll want to take a look at git filter-branch, the first example in particular.

Upvotes: 3

qqx
qqx

Reputation: 19495

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.

Upvotes: 10

cduffin
cduffin

Reputation: 210

git rm <file>

Should remove the file from the repo for you.

Upvotes: 4

Related Questions