2

These are the lines in my .gitignore concerning the files generated by flutter pub run build_runner build --delete-conflicting-outputs

*.freezed.dart
*.g.dart 

I tried

git rm -rf --cached .
git add .

and still *.freezed.dart and *.g.dart get added again

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
user3808307
  • 2,270
  • 9
  • 45
  • 99

3 Answers3

5

If I'm understanding your question correctly; if the files have been previously tracked by git then you need to remove the files then commit those changes to the repository to remove them from git but keeps the local copies.

git rm -r --cached .
git add .
git commit -m "remove ignored files"

Alternatively, you could simply remove the file/dir directly:

git rm -r --cached <file>

File/dir should no longer be tracked following next commit

  • Tracked and not previously tracked files get added- I even 1 deleted them manually,2 added, 3 commited, 4 pushed, 5 generated them again, and then 6 add, 7 commit again, and they get added to the new commit – user3808307 Nov 26 '21 at 19:21
  • 1
    gitignore doesn't need '*' before the file/dir would be my only other suggestion. however I found a thread that may be able to assist you better. https://stackoverflow.com/questions/1274057/how-can-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitign?noredirect=1&lq=1 – over9stacks Nov 26 '21 at 19:31
  • I'll check it out, Thank you – user3808307 Nov 26 '21 at 20:04
1

I don't understand why, but I changed

*.freezed.dart
*.g.dart 

for

*.g.dart 
*.freezed.dart

and it started working

user3808307
  • 2,270
  • 9
  • 45
  • 99
  • 1
    If you installed Git 2.34.0, it has a bug in `.gitignore` handling, fixed in Git 2.34.1. Exactly what this bug does wrong is not clear to me but that's one possibility. More likely though, I suspect you had saved the `.gitignore` file as UTF-16 earlier, and as UTF-8 this time. – torek Nov 27 '21 at 02:55
0

As commented, Git 2.34.1 fixes a regression around .gitignore.

The discussion on the Git mailing list reveals an issue around commit f652672 ("dir: select directories correctly")

While not directly related to your case (which ignores only files, not folders), check if upgrading to 2.34.1 helps.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I upgraded an it didn't work – user3808307 Nov 29 '21 at 11:59
  • @user3808307 Strange indeed. Can you reproduce the case where it is not working, and check that `git check-ignore -v -- a/file/which/should/be/ignored` is not ignored that that `git check-ignore` command tool? – VonC Nov 29 '21 at 13:02