Last active
December 7, 2024 02:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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