0

I want gitignore a file that is already committed and pushed to master;

Meaning, I want to ignore any change of that file.

But after I add the path in gitignore, it is still included in commit and pushed when I use

git add .

how do I ignore such file ?

Isaac Sim
  • 539
  • 1
  • 7
  • 23
  • Possible duplicate of [Ignore changes to a tracked file](https://stackoverflow.com/questions/32251037/ignore-changes-to-a-tracked-file) – user3942918 Nov 14 '18 at 04:55
  • 1
    Possible duplicate of [Can I 'git commit' a file and ignore its content changes?](https://stackoverflow.com/questions/3319479/can-i-git-commit-a-file-and-ignore-its-content-changes) – 1615903 Nov 14 '18 at 07:20

2 Answers2

2

You cannot. Once the file is in Git repo it is in the Git repo. You have to remove the file from Git repo in order for .gitignore to kick in and start ignoring the file.

It is pretty simple - it is either the file is in repo and tracked. Or the file is not in the repo and not tracked.

.gitignore helps with the second case when there are files which are NOT in the repo and you do not want Git constantly reminding you that you might want to commit those files.

anvk
  • 1,183
  • 8
  • 10
  • Thank you for the answer, but I checked the other answer since it is more specific and described in details with references. – Isaac Sim Nov 14 '18 at 05:08
  • No worries at all. The main thing we solved and explained your problem. Cheers! – anvk Nov 14 '18 at 12:31
0
  1. If you want the file to be removed altogether, you can delete the file locally, commit and push to master.

Remember, gitignore will only work for files, not yet pushed to remote. If already pushed to remote then, it will not work.

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected

  1. If you want to keep the file in master and ignore only your local changes, you can update git exclude file located in $GIT_DIR/info/exclude.

Read more information on gitignore

Read more information on ignore files locally in this stackoverflow Q&A

Community
  • 1
  • 1
Venkataraman R
  • 12,181
  • 2
  • 31
  • 58