Android Studio version control keeps adding build dir to commits

Viewed 391

So when I go to make a commit, I have to uncheck the app/build directory from the commit. I want to remove these files from being tracked.

Does my .gitignore file look correct?

build/
app/build/
.idea
.gradle

I've tried

git rm -r --cached .
git add .

Which appears to work, git status shows all build files have been deleted. So then I do a commit, and the files are deleted. But after building and the files changing, they show up on my next commit. Why is this, and why can't I untrack these files?

1 Answers

Looks like build directory already in index. Use

git rm -r --cached . 
git add .

to remove untracked files then commit changes.

But even better to remove files from the history:

git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch <path-to-build-dir>' --prune-empty -f -- --all

But in this case you have to use force push to update server history also.

Related