Ignore space difference in context line when applying git patch

1.1k views Asked by At

I'm trying to apply patch generated from some git repository. Patch context line looks like this

else if ( o is Item )

and in my code it looks like this

else if (o is Item)

When I apply patch

$ git apply -v --check --directory=myroot --ignore-space-change --ignore-whitespace ../patches/0003-some-name.patch

it says that

error: while searching for:

and provides the context block which has differences only in spaces mentioned above. When I fix the issue with the spaces the problem goes away. Is there a way to specify that spaces inside of context line can be ignored?

1

There are 1 answers

2
eckes On BEST ANSWER

As long as we're just talking about whitespace: git apply has the --ignore-whitespace option:

When applying a patch, ignore changes in whitespace in context lines if necessary

This should help you. Reads like someone had the same issues like you before :-)

If it's not just a whitespace problem in context lines, I usually use git apply with the --reject option: hunks that could be applied will be applied, those with problems are stored in a .rej file parallel to the patched file.