My problem: cygwin git doesn't seem to correctly prompt for credentials when using https:// URLs, so I used username and password in the URL. Unfortunately when I did a "get pull" it auto-commited a message with the full URL including password. I didn't notice this until after I had pushed the changes.
How do I edit old commit messages to eradicate the password in the URL?
My shared git repo is on my own server. I can do surgery on the repo if necessary.
Instructions on how to change my configuration (i.e. don't use Cygwin, don't use https) are unnecessary -- I'm trying to deal with what is already done.
Yes, I can and will burn the password but I'd still like to fix it.
You can modify the most recent commit in the same branch by running git commit --amend. This command is convenient for adding new or updated files to the previous commit. It is also a simple way to edit or add comments to the previous commit. Use git commit --amend to modify the most recent commit.
To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.
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-repo tool or the BFG Repo-Cleaner open source tool.
To completely remove a file from a git repository and its history, use these commands.
# Check out the remote repo
git clone git://host/path/repo.git
cd repo
# Clobber the file in your checkout
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch file-to-purge.txt' --prune empty --tag-name-filter cat -- --all
# Make sure you don't accidentally commit the file again
echo file-to-purge.txt >> .gitignore
git add .gitignore
git commit -m "Prevent accidentally committing this again" .gitignore
# Push the edited repo. This will break other people's clones, if any.
git push origin master --force
For more information, remove sensitive data guide at GitHub will help you.
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