如果你是想实现"只跟踪特定文件,忽略其他所有文件",则需要:
先在 .gitignore 中添加 * 忽略所有文件
然后使用 ! 来排除要跟踪的文件,例如:
* !important-file.txt !*.cpp