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:
- Add the file path into
.gitignore
file. - Remove the commited file from the git cache by
git rm --cached bar/foo.log
- 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!