0

it seems there are already "simlilar" answers, but my situation is

  • I'm working on a public branch with many teammates
  • file "a.txt" was commited and pushed
  • I add "a.txt" in .gitignore
  • I run git rm --cached a.txt
  • and "a.txt" does been ignored in my local branch, then I push it
  • but seems my teammates keep pushing this file back, everytime I pull from remote, "a.txt" is not ignored

so should I ask all my teammates to run git rm --cached a.txt in their local branch?

(a.txt is the classic "package-lock.json", due to diff versions among local machines and servers)

Littlee
  • 3,791
  • 6
  • 29
  • 61
  • A file that is in a commit will be copied to Git's index by any action that checks out that commit. Once the file is in Git's index, it's no longer an *untracked file* and cannot be ignored. It can only become untracked again by removing the file from Git's index (using `git rm` for instance, or by checking out some other commit in which the file *does not* exist). – torek Aug 15 '22 at 08:36
  • In short, only untracked files can be ignored. Your method (of removing it) works to achieve this. That won't make *other people* remove *their* version. And, as other answers noted, package-lock.json should not be ignored anyway. – torek Aug 15 '22 at 08:37

1 Answers1

1

I think they are adding a.txt back. If you also add .gitignore and push, then they probably won't add it again.

Note: package-lock.json is intended to be included in source control. See: here