Skip to content

Instantly share code, notes, and snippets.

@Wind010
Last active December 7, 2024 02:00
Show Gist options
  • Save Wind010/a16d42872a89eda563f901fdb407e152 to your computer and use it in GitHub Desktop.
Save Wind010/a16d42872a89eda563f901fdb407e152 to your computer and use it in GitHub Desktop.
Remove files from git history on owned git repo. Does not rid that file history from pull requests.
pip install git-filter-repo
$filesToDelete = @("some.txt", "other.txt")
$excludeFolders = @("template")
Get-ChildItem -Path . -Recurse -File | Where-Object {
$filesToDelete.Contains($_.Name) -and
-not $excludeFolders.Contains($_.Directory.Name)
} | % { git filter-repo --path $_.FullName --invert-paths --Force }
# Also just git filter-repo --path-glob '**/some.txt' --path-glob '**/other.txt' --invert-paths --force
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push origin --force --all
git push origin --force --tags
# May require adding origin again:
# git remote add "origin" [email protected]:User/UserRepo.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment