If you want to remove a file permanently, you must wish to there are not change log left in Git history. Otherwise, others still could see the content in the Git repository.
There are two methods for this task:
git filter-branch
Suppose you want to remove ./config/passwd
from Git:
|
Remember to add your sensitive file to .gitignore:
|
Then you’d better push to remote:
|
Tell your collaborators to rebase:
|
BFG repo-cleaner
Use BFG Repo-Cleaner.
BFG
provides a faster, simpler alternative to git filter-branch
for removing sensitive data. It’s very quickly, usually 10 - 720x faster than git filter-branch
.
Note: bfg
will leave your latest commit untouched. It’s designed to protect you from making mistakes. You should explicitly delete the file, commit the deletion, then clean up the history to remove it.
Suppose you want to remove the file ./config/password
:
|
Then use git push
to push to the remote repository.
Join my Email List for more insights, It's Free!😋