Skip to content

Instantly share code, notes, and snippets.

@qin-yu
Last active April 6, 2020 20:13
Show Gist options
  • Save qin-yu/e2fd6e6a3b7228957409fb7e30818b99 to your computer and use it in GitHub Desktop.
Save qin-yu/e2fd6e6a3b7228957409fb7e30818b99 to your computer and use it in GitHub Desktop.
How to detect and delete large file throughout history

Delete Files in Git History

How to detect and delete large file throughout history

  1. Push and see what files are rejected:

    $ git push
  2. Then it will show the path of the large file in a specific commit, delete the file throughout git history using this path:

    $ git filter-branch --force --index-filter \
        "git rm --cached --ignore-unmatch PATH-TO-LARGE-FILE" \
        --prune-empty --tag-name-filter cat -- --all

    However, note that if the file existed in another location at some point, that was not deleted, so push again to see the path if you fail to recall.

  3. Repeat 1 and 2 until it was deleted completely, then

    $ git push --force

How to untrack files based on changed .gitignore

  1. recursively -r remove rm files from index --cached
git rm -r --cached .
  1. add add everything again
git add .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment