如何忽略已提交到 Git 的文件 (例如 CMakeLists.txt.user)
对于已经被提交到 Git 的文件,即使在 '.gitignore' 文件中忽略了该文件,Git 仍然会跟踪并将其包含在版本控制中。
如果你想忽略已经被提交的文件,需要执行以下步骤:
- 从 Git 中删除该文件:
git rm --cached CMakeLists.txt.user。 - 将该文件添加到 '.gitignore' 文件中。
- 提交更改:
git commit -m 'Removed CMakeLists.txt.user and added to .gitignore'
这样,Git 就不再跟踪该文件,并且在将来的提交中将忽略它。
原文地址: https://www.cveoy.top/t/topic/nzMW 著作权归作者所有。请勿转载和采集!