How to ignore previously committed file
Ignoring a previously committed file
If you want to ignore a file that you’ve committed in the past, you’ll need to delete the file from your repository and then add a .gitignore
rule for it. Using the --cached
option with git rm
means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
$ echo debug.log >> .gitignore
$ git rm --cached debug.log
rm 'debug.log'
$ git commit -m "Start ignoring debug.log"
You can omit the --cached
option if you want to delete the file from both the repository and your local file system.
Cameron McKenzie is an AWS Certified AI Practitioner, Machine Learning Engineer, Solutions Architect and author of many popular books in the software development and Cloud Computing space. His growing YouTube channel training devs in Java, Spring, AI and ML has well over 30,000 subscribers.