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?
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?
I figured out this problem as instructed below,
git checkout -b new_branch
and commit somethinggit diff master --no-color > your_patch_file.patch
git checkout master
git apply your_patch_file_name.patch
Or you can run your git commands on Git Bash, probably you won't encounter any problem.
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.
Do you have coloured output enabled by default?
If git diff 4ee42367 8c650199
shows up coloured in your terminal then the colour codes will get output to the patch file
Then git apply
will fail with error: unrecognized input
In this case try instead with git diff --no-color
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
In my case problem was that I was generating the patch in PowerShell in Windows and then trying to apply that patch in Linux.
After looking frantatically on web for hours I found problem was due to PowerShell. I then created the patch using git bash in Windows and applied that on the Linux without any issue.
Looks like there might charset differernce or powershell might adding some characters which git did not understant on Linux.
Posted my answer here as it might help people who land up on this question with this error.