gitignore,跟踪所有具有某种扩展名的文件,除了一个特定文件

gitignore, track all files with some extension, except one specific file

我不需要忽略样本中某个扩展名 (json) 的所有文件,而是只忽略一个具有相同扩展名的特定文件,例如:

# Ignore all files by default, but scan all directories
*
!*/

# track all json files
!*.json

# but don't track this one
Target.json

问题是 Target.json 被跟踪了,我该如何忽略它?

首先确保 Target.json 尚未版本化:

git rm --cached Target.json

这将允许应用忽略规则。