Skip to content

Instantly share code, notes, and snippets.

@dennyweiss
Created March 7, 2018 14:36
Show Gist options
  • Save dennyweiss/e4e50d74bd3aac971c6559a109c4ece3 to your computer and use it in GitHub Desktop.
Save dennyweiss/e4e50d74bd3aac971c6559a109c4ece3 to your computer and use it in GitHub Desktop.
Remove directory from git history
# unashamed copied from https://stackoverflow.com/a/17824718
RELATIVE_DIRECTORY="node_modules"
git filter-branch --tree-filter "rm -rf ${RELATIVE_DIRECTORY}" --prune-empty HEAD
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
echo "${RELATIVE_DIRECTORY}/ >> .gitignore
git add .gitignore
git commit -m "Removing ${RELATIVE_DIRECTORY} from git history"
git gc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment