Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to apply git diff, "No valid patches in input"

I'm creating a powershell script with the goal of going through several git branches, saving a patch of the working changes, switching to the trunk branch to pull remote commits, then switching back to the working branch and reapplying the working changes.

Here is the method I am testing specifically:

git diff > test.patch
git restore .
*do main branch operation*
git apply test.patch

However when I try to apply the patch that I have just created I get an error:

error: No valid patches in input (allow with "--allow-empty")

Does anyone see what I'm doing wrong here?

Git version: 2.35.2.windows.1

Powershell version: 5.1.19041.1320

like image 834
Ridiculon Avatar asked Sep 11 '25 05:09

Ridiculon


1 Answers

Likely windows changed the line terminator to CRLF. Get it back to LF.

For anyone else struggling - I tried this, but I also had to re-save the patch file in UTF-8 format for git to recognise it.

like image 86
penguinflip Avatar answered Sep 12 '25 20:09

penguinflip