Reputation: 261
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?
Upvotes: 26
Views: 24238
Reputation: 31
Go the same problem after generating the patch from PowerShell. The classic 'dos2unix' command solved the issue
Upvotes: 0
Reputation: 973
Just like @irsis, I also ran into this problem when I was generating the patch in PowerShell on Windows and then trying to apply that patch on Linux. Thanks to irisis, I find out the way to apply it. You don't need to install git shell on Windows, but with cmd.exe to generate the patch again. That patch can be applied on Linux. You can find that the patch file can be only half the size of that one generated in PowerShell.
Put in other words, use git command in CMD instead of PowerShell to generate patch file, while better to use --no-color option in case other issue.
Upvotes: 0
Reputation: 1054
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.
Upvotes: 2
Reputation: 1257
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.
Upvotes: 23
Reputation: 30646
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
Upvotes: 8
Reputation: 461
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.
Upvotes: 30
Reputation: 33873
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
Upvotes: 9