Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git apply : error trailing whitespace

Tags:

git

patch

Lately, I've been playing a little bit with git. I'm trying to simulate to apply a patch to my master branch, this patch comprehends a commit where I added some comments to a java operation. I generated the patch using git format-patch. Then I switched to my master branch to apply the patch. the following errors occurred when executing the git apply command :

path/to/my/patch/file: line x
path/to/my/patch/file: line x+1
path/to/my/patch/file: line x+2
path/to/my/patch/file: line x+3

I note that I also tried the following arguments : --ignore-space, ignore-whitespace,

like image 353
ben S Avatar asked Mar 08 '26 02:03

ben S


1 Answers

If you are not concerned with applying trailing whitespaces to your repo you can use the flag --whitespace=fix to ignore the error and apply anyway

git apply --whitespace=fix your.patch

I have heard some people say that the default is to warn and apply the patch, but that has not been my experience and the above solution seems to do what I want.

like image 138
Derek Ekins Avatar answered Mar 10 '26 15:03

Derek Ekins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!