[Git] How to ignore the commited file

In Git, we can ignore to track of a file or folder by adding their paths into the file .gitignore. However, sometimes we could mistakenly commit and push file and folders that are not needed to be tracked by Git. In such case, .gitignore will be not working.

The issue can be solved by the below steps:

  1. Add the file path into .gitignore file.
  2. Remove the commited file from the git cache by
git rm --cached bar/foo.log
  1. Commit the changes by
git commit -m "xxx"

After executing the above steps, you can see the file bar/foo.log is still there but will be not tracked by Git.


If this post helped you to solve a problem or provided you with new insights, please upvote it and share your experience in the comments below. Your comments can help others who may be facing similar challenges. Thank you!
Buy Me A Coffee
DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !