From cec9482e50c55f89f73cebf4693f61fb41ec0e5e Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 23 Nov 2024 13:38:49 -0800 Subject: [PATCH] wip --- Documentation/curated-examples-from-issues.md | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/curated-examples-from-issues.md diff --git a/Documentation/curated-examples-from-issues.md b/Documentation/curated-examples-from-issues.md new file mode 100644 index 00000000..4a73640f --- /dev/null +++ b/Documentation/curated-examples-from-issues.md @@ -0,0 +1,105 @@ +# Curated examples from issues + +Lots of people have filed issues against git-filter-repo, and many times it +boils down into questions of "How do I?" or "Why doesn't this work?" + +I thought I'd collect a bunch of these as example repository filterings +that others may be interested in. + +## Table of Contents + + * [Adding files to root commits](#adding-files-to-root-commits) + * [Purge a large list of files](#purge-a-large-list-of-files) + +## Adding files to root commits + + + +Here's an example that will take `/path/to/existing/README.md` and +store it as `README.md` in the repository, and take +`/home/myusers/mymodule.gitignore` and store it as `src/.gitignore` in +the repository: + +``` +git filter-repo --commit-callback "if not commit.parents: commit.file_changes += [ + FileChange(b'M', b'README.md', b'$(git hash-object -w '/path/to/existing/README.md')', b'100644'), + FileChange(b'M', b'src/.gitignore', b'$(git hash-object -w '/home/myusers/mymodule.gitignore')', b'100644')]" +``` + +Alternatively, you could also use the [insert-beginning contrib script](../contrib/filter-repo-demos/insert-beginning). + +## Purge a large list of files + +Stick all the files in some file (one per line), +e.g. ../DELETED_FILENAMES.txt, and then run + +``` +git filter-repo --invert-paths --paths-from-file ../DELETED_FILENAMES.txt +``` + + + nuking files previously deleted + + + extract library to separate repo + + + replace words in all commit messages + + + only keep files in repository that are present in latest commit + + + renormalize all end-of-line characters + + + removing spaces at end of lines (user example) + + + having both exclude and include rules for filenames + + + setting executable bit + + + another example for removing paths with a certain extension + + + removing a directory + + + NFD/NFC conversion + + + make committer match current user (to get past push hooks) + + + handling special characters, e.g. accents in names + + + handling repository corruption (old original objects are corrupt) + + + removing all files with a backslash in them (final example is best) + + + replace a binary blob in history + + + callback for lint-history + + + using replace refs to delete old history + + + replacing pngs with compressed alternative + (#537 also used a change.blob_id thingy) + + + + need for a multi-step filtering to avoid path collisions or ordering issues + + + Two things: + textwrap.dedent + easier example of using git-filter-repo as a library