You will have to clear the existing git cache first.
Remove the cache of all the files
git rm -r --cached .
Remove the cache of specific file
git rm -r --cached <file_name.ext>
Once you clear the existing cache, add/stage file/files in the current directory and commit
git add . // To add all the files
git add <file_name.ext> // To add specific file
git commit -m "Suitable Message"
As pointed out by Scott Biggs in comment that "This works for both adding a file that was once ignored as well as ignoring a file that was once tracked"
Assuming here that your current working directory is empty.
You can check what files git is currently tracking by using git ls-files. If you have a lot of files, you can use git ls-files | grep hello.txt to find if git is tracking that specific file.
If it is tracking it, then use git rm hello.txt to untrack it (as Tim mentioned in his comment). Perhaps commit that untracked state first and then add it in to your .gitignore on your next commit. I have seen some funky behavior in the past when trying to ignore and remove in the same commit.
You can resolve this issue by deleting the cache of those specific files where you are getting this issue.
The issue you mentioned occurs when you have committed some specific files once and then you are adding them in .gitignore later.