Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git apply error : unrecognized input

Tags:

git

 git diff 4ee42367 8c650199 > changes2.patch
 git checkout newBranch
 git apply changes2.patch
 error: unrecognized input

When i tried to apply the changes i'll get the error. What i'm doing wrong?

like image 243
Nik Gaponov Avatar asked Jul 26 '18 15:07

Nik Gaponov


3 Answers

I figured out this problem as instructed below,

  1. git checkout -b new_branch and commit something
  2. git diff master --no-color > your_patch_file.patch
  3. Open "your_patch_file.patch" file with NotePad++ and edit that file like,
    • Encoding > Convert to UTF-8
    • Edit > EOL Conversion > Unix (LF)
    • Save file
  4. git checkout master
  5. git apply your_patch_file_name.patch

Or you can run your git commands on Git Bash, probably you won't encounter any problem.

like image 100
Levent Tugay Kaplan Avatar answered Sep 21 '22 12:09

Levent Tugay Kaplan


In case anyone else has this issue: for me, Powershell was the culprit. using Anentropic's answer from within git bash resulted in a "good" (readable) patch.

like image 38
MCO Avatar answered Sep 17 '22 12:09

MCO


For those running this form within Powershell, here is another post with information about the encoding error, and why it is happening.

If you're just looking for an answer, you can edit your powershell profile:

PS> code $profile

and add

$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'

This can cause other issues, so use at your own risk.

If you just want to run it for a single instance, you can do this

$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
git diff > change.patch
git checkout otherbranch
git apply change.patch
like image 30
Nate Avatar answered Sep 18 '22 12:09

Nate