git-filter-repo
git-filter-repo copied to clipboard
Missing files when retaining files in root while also renaming subdirectory to root
When trying to rename a subdirectory to root (--path-rename subdirectory/:
) while also trying to keep some files in root (--path some-file
), it looks like there are some cases where the root file will not be kept (and also no error will be thrown).
I'm able to replicate the issue by setting up a repo as follows:
git clone https://github.com/newren/git-filter-repo.git test-repo
cd test-repo
echo "example" > release/Makefile
git add release/Makefile
git commit -m "Add release/Makefile"
git rm release/Makefile
git commit -m "Delete release/Makefile"
Then running the git-filter-repo
command to keep two files in root while also renaming a subdirectory:
git-filter-repo --force --path README.md --path Makefile --path release --path-rename release/:
The resulting repo is then missing the Makefile
that I wanted to keep.
Is git-filter-repo
able to support this case where the subdirectory historically had a conflicting filename?
Can I somehow do the subdirectory rename while excluding that one historical file in the subdirectory (release/Makefile
in this case)?
(I suspect this issue might also be related to a question asked here: https://stackoverflow.com/questions/67786357/use-git-filter-repo-to-move-a-subdirectory-to-root-while-retaining-files-in-root - although none of their command variations worked for me.)
Once you have colliding filenames within a single filtering invocation, all bets are off. And there's not a lot I can do to fix that.
However, you could do this in multiple filtering invocations:
git filter-repo --path release/Makefile --invert-paths
git filter-repo --path README.md --path Makefile --path release --path-rename release/:
Does that help? (Would it have helped had I answered about a year sooner?)