Created
May 25, 2025 08:44
-
-
Save EliteMasterEric/ef5b39e9a85182d2852960994baec721 to your computer and use it in GitHub Desktop.
git-filter-repo script used to remap assets module commits
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
| // Commands for rewriting commit history to remove certain files. | |
| // Requires installing git-filter-repo: https://github.com/newren/git-filter-repo | |
| // Any one of these commands creates a new, incompatible Git history starting with any commits that have changed, | |
| // so only do it when absolutely necessary,and be prepared to run several of these commands before you have a stable history again. | |
| // Remove files from the given list from a repo. | |
| git filter-repo --invert-paths --paths-from-file ../to-sanitize-assets.txt --force | |
| // Utilize the commit map to fix commit links. | |
| // If you ran the sanitize command on a submodule, use this to link them back up. | |
| git filter-repo --commit-callback " | |
| for change in commit.file_changes: | |
| if change.filename == b'assets': | |
| map_file = open('../Funkin-assets-secret/.git/filter-repo/commit-map', 'r') | |
| map_lines = map_file.readlines() | |
| print('Read {} lines from map file'.format(len(map_lines))) | |
| found = False | |
| for map_entry in map_lines: | |
| map_entry = map_entry.rstrip().split(' ') | |
| map_entry[0] = map_entry[0].encode('ascii') | |
| map_entry[1] = map_entry[1].encode('ascii') | |
| if change.blob_id == map_entry[0]: | |
| change.blob_id = map_entry[1] | |
| found = True | |
| print('Replaced hashes: {} -> {}'.format(map_entry[0], map_entry[1])) | |
| break | |
| if not found: | |
| # Someone force-pushed commit after commiting the main repo? | |
| print('WARN: Can\'t find replacement for hash {} in commit {}'.format(change.blob_id, commit.message)) | |
| " | |
| // After doing the submodule remap, I found that some of the commits were mapped to a null hash. | |
| // Use this command malformed commit hashes with a specific hash. | |
| git filter-repo --commit-callback " | |
| for change in commit.file_changes: | |
| if change.filename == b'assets': | |
| malformed_hash = '0000000000000000000000000000000000000000'.encode('ascii') | |
| valid_hash = 'abbbc89a83f48317568b5b25eaf831ae16f88a8c'.encode('ascii') | |
| if change.blob_id == malformed_hash: | |
| change.blob_id = valid_hash | |
| print('Replaced malformed hash: {} -> {}'.format(malformed_hash, valid_hash)) | |
| " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment