Deleting a file with a password in it doesn’t remove it from history. To check whether a string was ever committed, I’d let git grep search every commit.
git grep -n 'API_KEY' $(git rev-list --all)
git rev-list --all lists every commit on every branch and tag, and git grep searches the files of each one. A hit looks like b416670...:config/.env:1:API_KEY=abc: the commit, the path, the line number and the line. So even if the file was removed three commits later, you see where it lived.
To narrow it to one path, add a pathspec after --:
git grep -n 'password' $(git rev-list --all) -- '*.yml'
On a big repository this is slow, and the list of commits can get so long that the shell refuses it with an “argument list too long” error. Then loop through the commits in batches with xargs, or use a dedicated secret scanner.
Finding it is the easy part. If a real key or password shows up, assume it’s leaked once the repository was pushed anywhere. Revoke or rotate it first. Rewriting history afterwards is optional cleanup, because forks, clones and caches may still have the old commits.
Further reading: git-grep documentation, git-rev-list documentation