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?
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.
I figured out this problem as instructed below,
git checkout -b new_branch and commit somethinggit diff master --no-color > your_patch_file.patchgit checkout mastergit apply your_patch_file_name.patchOr you can run your git commands on Git Bash, probably you won't encounter any problem.
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