How to make a patch ignore the file index using "git apply"?
Asked Answered
V

2

7

I'm trying to apply a .patch file to my source, but it fails because my file index (10655) is older than the patch index (10755).

Now I know that I can just modify the patch's file index but I would like to know if there is any way using git to make a patch ignore the file index differences?

Vickey answered 17/11, 2011 at 17:3 Comment(0)
B
5

You might find the patch application less strict about what it is applying to. IE, just run 'patch -p0 < file' and it should apply it and then you can commit it.

The downside is that you'll loose the authoring information, etc, so you might want to use --author along with the commit.

Besnard answered 17/11, 2011 at 18:30 Comment(0)
B
0

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
Baboon answered 15/6, 2023 at 18:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.