已编辑.gitignore仍无法忽略test-output文件夹及classes.html,该如何解决?
解决.gitignore忽略test-output文件夹不生效的问题
1. 修正.gitignore配置
如果要忽略整个test-output文件夹(包含其中所有文件,包括classes.html),只需要在.gitignore中添加一行:
test-output/
注:末尾的斜杠
/是关键,用来指定这是一个文件夹,而非同名文件。同时写test-output/和test-output/classes.html属于重复配置,无需保留后者。
2. 处理已被Git追踪的文件
如果之前test-output文件夹或其中的classes.html已经被Git提交过(即存在于Git版本历史中),后续的.gitignore配置不会对这些已追踪文件生效,需要先移除它们的追踪状态:
- 移除整个文件夹的追踪(推荐,匹配你忽略整个文件夹的需求):
git rm -r --cached test-output/ - 若仅需移除单个文件的追踪:
git rm --cached test-output/classes.html
执行完移除命令后,提交修改:
git commit -m "停止追踪test-output文件夹"
3. 验证配置
执行git status命令,确认test-output相关文件不再出现在"Changes to be committed"或"Untracked files"列表中,之后该文件夹的所有内容都会被Git忽略。
内容的提问来源于stack exchange,提问作者M Thomas Mary
相关产品推荐
相关产品推荐

