On a commit I accidentally included a password. How do I remove this commit from the repository?
The push went to github so It's important that the commit be removed completely from the history.
Entering Git Username and Password in Remote URL To prevent Git from asking for your username and password, you can enter the login credentials in the URL as shown. The main drawback of this method that your username and password will be saved in the command in the Shell history file.
If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history. To entirely remove unwanted files from a repository's history you can use either the git filter-branch command or the BFG Repo-Cleaner open source tool.
If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository. Using an HTTPS remote URL has some advantages: it's easier to set up than SSH, and usually works through strict firewalls and proxies.
You should do as follow:
git log --oneline -S <COMMIT_SEARCH_PATTERN>
# Copy the commit hash
git rebase - i <COMMIT_HASH>~1
# Change the marker to **drop**
# Exit from the editor
git rebase --continue
git push --force
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With