Sometimes you work on a project, you accidentally push some credential information in the remote repository.
credential information means API token, User Email password which used for the test, SHA key, Database host username password, etc.
You can commit again by removing those credential info from the file and you think no one can see, here you will make mistake again.
Many crawling bots will crawl the git repo every time whether or repo public or on that case, it's making very risky for your project repo.
Delete commits from a branch in Git
I would like to know how to delete a commit. By delete, I mean it is as if I didn't make that commit, and when I do a…
This very acceptable solution. you can remove commit by
git reset --hard <sha1-commit-id> and
git push origin HEAD --force
but you have done many commits after this issue. SO it will be very hard for you to take backup and remove commit and force push again.
If you are human like me, you don't care about all those commit records you just need to flush all commit history anyhow possible but don't know the possible solution then this story is for you. Even if you do not like me also for you too. Maybe it might help you in the future. :D
Remember this will remove your old commit history completely, You can’t recover it again.
You have to create an orphan branch by
git checkout — orphan orphan_branch
then add all file and commit
git add .
git commit -m "new commit"
delete the branch you want to delete in my case its master.
git branch -D master
rename the current branch master
git branch -m master
then push the branch
git push -f origin master