4

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?

rosghub
  • 8,924
  • 4
  • 24
  • 37
  • _"But after building and the files changing, they show up on my next commit."_ - can you show the exact steps you use to make the next commit, and the output of git status between each action? – 1615903 Nov 14 '17 at 06:50
  • It seems running `git reset HEAD` has fixed the issue. I am curious why if anyone knows (was suggested in page linked in comments of answer below) – rosghub Nov 14 '17 at 07:03

1 Answers1

3

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.

Northern Poet
  • 1,955
  • 1
  • 12
  • 17
  • Any idea why `git update-index ...` produces `fatal: Unable to mark file build`? – rosghub Nov 14 '17 at 06:47
  • Please try to including full path to the build directory – Northern Poet Nov 14 '17 at 06:49
  • Here is a full reference: https://stackoverflow.com/questions/12920652/git-update-index-assume-unchanged-returns-fatal-unable-to-mark-file – Northern Poet Nov 14 '17 at 06:50
  • Yes tried using the full path to build directory same result. Even tried using full path to individual files. Same result. – rosghub Nov 14 '17 at 06:53
  • `--assume-unchanged` is absolutely not appropriate for this situation. It does not "remove files from the history" as you claim in your answer, it only tells git to not check it for changes and should ONLY be used for performance improvement. – 1615903 Nov 14 '17 at 06:54
  • Actually may have solved my problems with `git reset HEAD`. Anyone know why this worked? – rosghub Nov 14 '17 at 06:57
  • 1
    @1615903 You're correct, I was mistaken. I fixed the command in answer to solve it. – Northern Poet Nov 14 '17 at 06:59
  • @jefferson, `git rm --cached` will **remove the dir from the stage**. When you commit, dir will be removed. `git reset HEAD` will simply reset `build` dir status in the staging area. – Northern Poet Nov 14 '17 at 07:05
  • Well it seems to have fixed my issue for the time being. Like I said I've removed the directory from index with `rm --cached` and the commit shows they were deleted but they come back after the next build. I just changed some source files and ran a build (which would reproduce) and the build dir was not listed in the commit. Will leave the question open for a day in case I see the issue again tomorrow. Thanks – rosghub Nov 14 '17 at 07:11