2 weeks ago, I commited config of my application which had my password, it's not very useful. How can I remove the file from the commit history and make sure it doesn't get re-commited?
I want to remove the file from all commits tree because it contains my passwords.
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a .gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
gitignore file allows you to ignore files in a Git repository. You may not want to include all the files in your local copy of a project in your commits. For instance, you may not want to commit compiled code, or system logs, or config files. To ignore files, you can specify which ones you want to ignore in .
Removing Files To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don't see it as an untracked file the next time around.
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
You can
git rm myConfigFile
echo myConfigFile > .gitignore
git add .gitignore
git commit -m "from now on, no more myConfigFile"
The other extreme approach (dangerous especially if you have already pushed your repo to a remote one) would be to entirely remove that file from the history of said repo:
git filter-branch --index-filter 'git update-index --remove myConfigFile' HEAD
(to use with care, and with a backup first)
The question How do I remove sensitive files from git’s history has more on that sensitive topic.
The problems with this process are twofold:
RECOVERING FROM UPSTREAM REBASE
" in the git-rebase
manpage.cp my-config config.tmp
git rm my-config
git commit -m 'removed config'
mv config.tmp my-config
echo my-config >> .gitignore
git add .gitignore
git commit -m 'ignore config'
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