In contrast to what the name "ignore" might suggest. .gitignore
is only consulted when you git add
files: in other words a file already added to the (index of the) repository will not be excluded based on the .gitignore
.
First you better modify the .gitignore
such that the file is no longer added. Add the following line to the .gitignore
file:
public/app/template.js
Next you need to exclude the file from the repository. Probably you don't want to remove the file from your file system, this can be done with:
git rm --cached public/app/template.js
The --cached
flag ensures the file will not be removed from your file system. (If not important, you can use git rm public/app/template.js
, but this will remove the file).
Background
The reason .gitignore
is not proactively used is because you sometimes might want to override the .gitignore
. Say for instance you don't want to track *.log
files, you can specify *.log
in the .gitignore
. But if there is a specific one you want to track you can add git add -f some.log
. The -f
flag forces git
to add the file.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…