I am needing the same thing, but for a different reason: I need to patch files that are stored in Git LFS which causes trouble to git apply
because git apply
uses the index state of the file (the LFS hash) instead of the workspace state (i.e. the state on the filesystem).
I also cannot use patch
because I also need the method to support git binary diffs, on which patch
fails with "git binary diffs are not supported". So the other solution does not work for me.
I wish there was an option to git apply
that would allow cleanly and easily ignoring the git repo, but I found none in my version of git (2.30.2).
First solution (hackish)
The idea is to disable git, temporarily.
mv .git .git-hidden-to-git-apply
git apply stuff.patch
mv .git-hidden-to-git-apply .git
Second solution (also hackish)
The idea is to run git apply
from outside of the git repo.
cd ..
git apply stuff.patch --directory=my_git_repo --unsafe-paths
cd my_git_repo