|
| 1 | +# Curated examples from issues |
| 2 | + |
| 3 | +Lots of people have filed issues against git-filter-repo, and many times it |
| 4 | +boils down into questions of "How do I?" or "Why doesn't this work?" |
| 5 | + |
| 6 | +I thought I'd collect a bunch of these as example repository filterings |
| 7 | +that others may be interested in. |
| 8 | + |
| 9 | +## Table of Contents |
| 10 | + |
| 11 | + * [Adding files to root commits](#adding-files-to-root-commits) |
| 12 | + * [Purge a large list of files](#purge-a-large-list-of-files) |
| 13 | + |
| 14 | +## Adding files to root commits |
| 15 | + |
| 16 | +<!-- https://github.com/newren/git-filter-repo/issues/21 --> |
| 17 | + |
| 18 | +Here's an example that will take `/path/to/existing/README.md` and |
| 19 | +store it as `README.md` in the repository, and take |
| 20 | +`/home/myusers/mymodule.gitignore` and store it as `src/.gitignore` in |
| 21 | +the repository: |
| 22 | + |
| 23 | +``` |
| 24 | +git filter-repo --commit-callback "if not commit.parents: commit.file_changes += [ |
| 25 | + FileChange(b'M', b'README.md', b'$(git hash-object -w '/path/to/existing/README.md')', b'100644'), |
| 26 | + FileChange(b'M', b'src/.gitignore', b'$(git hash-object -w '/home/myusers/mymodule.gitignore')', b'100644')]" |
| 27 | +``` |
| 28 | + |
| 29 | +Alternatively, you could also use the [insert-beginning contrib script](../contrib/filter-repo-demos/insert-beginning). |
| 30 | + |
| 31 | +## Purge a large list of files |
| 32 | + |
| 33 | +Stick all the files in some file (one per line), |
| 34 | +e.g. ../DELETED_FILENAMES.txt, and then run |
| 35 | + |
| 36 | +``` |
| 37 | +git filter-repo --invert-paths --paths-from-file ../DELETED_FILENAMES.txt |
| 38 | +``` |
| 39 | + |
| 40 | +<!-- https://github.com/newren/git-filter-repo/issues/63 --> |
| 41 | + nuking files previously deleted |
| 42 | + |
| 43 | +<!-- https://github.com/newren/git-filter-repo/issues/80 --> |
| 44 | + extract library to separate repo |
| 45 | + |
| 46 | +<!-- https://github.com/newren/git-filter-repo/issues/83 --> |
| 47 | + replace words in all commit messages |
| 48 | + |
| 49 | +<!-- https://github.com/newren/git-filter-repo/issues/91 --> |
| 50 | + only keep files in repository that are present in latest commit |
| 51 | + |
| 52 | +<!-- https://github.com/newren/git-filter-repo/issues/122 --> |
| 53 | + renormalize all end-of-line characters |
| 54 | + |
| 55 | +<!-- https://github.com/newren/git-filter-repo/issues/145 --> |
| 56 | + removing spaces at end of lines (user example) |
| 57 | + |
| 58 | +<!-- https://github.com/newren/git-filter-repo/issues/230 --> |
| 59 | + having both exclude and include rules for filenames |
| 60 | + |
| 61 | +<!-- https://github.com/newren/git-filter-repo/issues/268 --> |
| 62 | + setting executable bit |
| 63 | + |
| 64 | +<!-- https://github.com/newren/git-filter-repo/issues/274 --> |
| 65 | + another example for removing paths with a certain extension |
| 66 | + |
| 67 | +<!-- https://github.com/newren/git-filter-repo/issues/278 --> |
| 68 | + removing a directory |
| 69 | + |
| 70 | +<!-- https://github.com/newren/git-filter-repo/issues/296 --> |
| 71 | + NFD/NFC conversion |
| 72 | + |
| 73 | +<!-- https://github.com/newren/git-filter-repo/issues/379 --> |
| 74 | + make committer match current user (to get past push hooks) |
| 75 | + |
| 76 | +<!-- https://github.com/newren/git-filter-repo/issues/383 --> |
| 77 | + handling special characters, e.g. accents in names |
| 78 | + |
| 79 | +<!-- https://github.com/newren/git-filter-repo/issues/420 --> |
| 80 | + handling repository corruption (old original objects are corrupt) |
| 81 | + |
| 82 | +<!-- https://github.com/newren/git-filter-repo/issues/427 --> |
| 83 | + removing all files with a backslash in them (final example is best) |
| 84 | + |
| 85 | +<!-- https://github.com/newren/git-filter-repo/issues/436 --> |
| 86 | + replace a binary blob in history |
| 87 | + |
| 88 | +<!-- https://github.com/newren/git-filter-repo/pull/542 --> |
| 89 | + callback for lint-history |
| 90 | + |
| 91 | +<!-- https://github.com/newren/git-filter-repo/issues/300 --> |
| 92 | + using replace refs to delete old history |
| 93 | + |
| 94 | +<!-- https://github.com/newren/git-filter-repo/issues/492 --> |
| 95 | + replacing pngs with compressed alternative |
| 96 | + (#537 also used a change.blob_id thingy) |
| 97 | + |
| 98 | +<!-- https://github.com/newren/git-filter-repo/issues/490 --> |
| 99 | +<!-- https://github.com/newren/git-filter-repo/issues/504 --> |
| 100 | + need for a multi-step filtering to avoid path collisions or ordering issues |
| 101 | + |
| 102 | +<!-- https://lore.kernel.org/git/CABPp-BFqbiS8xsbLouNB41QTc5p0hEOy-EoV0Sjnp=xJEShkTw@mail.gmail.com/ --> |
| 103 | + Two things: |
| 104 | + textwrap.dedent |
| 105 | + easier example of using git-filter-repo as a library |
0 commit comments