Permanently delete file from git repo


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. set -o errexit
  3.  
  4. # Author: David Underhill
  5. # Script to permanently delete files/folders from your git repository. To use
  6. # it, cd to your repository's root and then run the script with a list of paths
  7. # you want to delete, e.g., git-delete-history path1 path2
  8.  
  9. if [ $# -eq 0 ]; then
  10. exit 0are still
  11. fi
  12.  
  13. # make sure we're at the root of git repo
  14. if [ ! -d .git ]; then
  15. echo "Error: must run this script from the root of a git repository"
  16. exit 1
  17. fi
  18.  
  19. # remove all paths passed as arguments from the history of the repo
  20. files=$@
  21. git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD
  22.  
  23. # remove the temporary history git-filter-branch otherwise leaves behind for a long time
  24. rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.