Let's say i have done 5 commits in my git project.
At Commit 4 i accidentally added my credentials.json file and pushed to repo.
At Commit 5 i removed the file and did a commit and pushed this change to repo.
Currently the file is not showing in latest commit. But if a user checks commit history, he can go to commit 4 and check the contents of my file.
How can i permanently remove the file from commit history so that it looks like the file was never added to the repo.
Note:-
i have already tried below command:-
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch Credentials.json" \
--prune-empty --tag-name-filter cat -- --all
It does not throw any error but the file is not removed from History.
Actually the file is inside /src folder. But the strange thing is that when i give the below command (including the full path):-
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch ~full-path/src/Credentials.json" --prune-empty --tag-name-filter cat -- --all
I get error as:- ~full-path/src/Credentials.json is outside repository.
Is it because i have already removed my file in commit 5?
What can i do in this scenario?
Is creating a new repo from scratch the only option?