I have created a diff of my changes from other branch called `main like so:
// while on another branch that is not `main`
git diff main > my-diff.patch
however when I run git apply my-diff.patch, I see that my file renames (using git mv) are not being respected. Instead, I see the renamed filed as deleted and the file that was created using git mv as an entirely new file.
How do I get git apply to respect my file renames I had used prior using git mv?
Git is a little peculiar about tracking file renames - in short, it doesn't.
This sort of makes sense, because git doesn't actually track changes at all - every commit is a snapshot of the entire repository. So although there's a "git mv" command, there isn't actually anywhere to record that you used it - all git records is the result, which is exactly the same as if you deleted the original file, and retyped the new one from memory.
What makes this a bit confusing is that git occasionally pretends to know what moving or copying files means. It does this by guessing when it looks at a diff that a creation and a deletion actually go together. It can do that guessing at any time, and some commands have options to make it not guess, or try harder to guess, when displaying things.
So "git apply" did exactly the right thing: it created a state of the repository equivalent to moving the file. Commit that state, and the file will show as renamed or not in all the same places as if you'd run "git mv".