Delete file from git history

Based on this article , I created a small script that should remove all occurrences of a file in whole git repo, all branches, tags and commits. script:

#!/usr/bin/env node var child_process = require('child_process'); if (process.argv.length < 3){ console.error('USAGE: git-forget path/to/file') process.exit(1); } var path = process.argv[2]; var phase = 0; function printLog(error, stdout, stderr) { if (error) { console.error('ERROR' + error); } console.log(++phase); console.log(stdout); } child_process.execSync('git filter-branch --force --index-filter \'git rm -f --cached --ignore-unmatch '+ path +'\' --prune-empty --tag-name-filter cat -- --all'); child_process.execSync('echo "' + path + '" >> .gitignore', printLog); child_process.execSync('git add .gitignore'); child_process.execSync('git commit -m "Add ' + path +' to .gitignore"',printLog) child_process.execSync('git push origin --force --all',printLog); child_process.execSync('git push origin --force --tags',printLog); 

This script worked on several repositories (which are private), and on a specific one it kept the original commit of the file that I was trying to delete. After running the script, I did this git log --all -- .npmrc and found the initial commit. What am I missing?

+7
git git-rewrite-history
source share
1 answer

I think what happened is that you forgot to tell other users of this repo so as not to merge your changes into a new story, but rather rebalance it. From the document you provided:

Tell your employees about reinstalling, not combining, any branches that they created from your old (damaged) storage history. One merger can return some or all of the tainted history that you simply went to the work of purification.

Try again with the same script, and make sure no one is entering a new story as a result of merging local changes with a new head.

+5
source share

All Articles