Completely remove every trace of git commit

前端 未结 1 981
自闭症患者
自闭症患者 2020-12-12 04:26

Following situation: I have a git repo with a lot of commits, and I want to remove a file that was introduced in a commit changed in a few and finally deleted in a commit. S

相关标签:
1条回答
  • 2020-12-12 05:00

    The canonical guide to removing the commit is here. It in essence gives two routes, git-filter-branch, and bfg.

    However, if you really mean completely remove, you are missing step 9 in that process, i.e. :

    git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
    git reflog expire --expire=now --all
    git gc --prune=now
    

    which will actually delete the unused references.

    Note also that if these are either sensitive data that should never have been committed, or they are just huge (so you don't want a git pull to pull them down again), you need to ensure they are removed from:

    • The upstream repo (and any other upstream repos)
    • All your collaborator's repos (so they don't push them back) - it's normally easier to ask them to delete their repo and reclone.

    Note also the comment in there about getting collaborators to rebase rather than merge.

    0 讨论(0)
提交回复
热议问题