问题描述
我运行的是Mac OSX 10.9.4(Mavericks),并且拥有2.8.2的git版本。我用一个全新的回购测试了这个。
mkdir gitest
cd gitest
git init
echomonkeyface> ; monkey.txt
git commit -m第一次提交
echomonkeyface farted> monkeyfart.txt
git add。
git diff HEAD> new.patch
rm monkeyfart.txt
git reset --hard HEAD
git apply new.patch --check
>致命:无法识别的输入
任何想法是什么导致了这个?可能是我的.gitconfig文件中的任何东西?
[user]
name = myusername
email = [email protected]
[color]
ui = always
[别名]
st =状态-sb -uall
lg = log --decorate --pretty = oneline --abbrev-commit --graph
undocommit = reset --soft HEAD ^
undopush = push -f origin HEAD ^:master
[core]
editor = vim
excludesfile =〜/ .gitignore_global
pager = less -r
[commit]
template =〜/ .gitmessage.txt
[filtermedia]
clean = git-media-clean%f
smudge = git-media-smudge%f
更新:
尽管下面链接的答案提供了关于问题可能出现的一些想法,但我的问题特别隐藏在我的配置中,因为没有颜色参数传入命令。这个答案是相关的,但我的问题和答案可能会对其他可能遇到类似问题的人有所帮助。
解决方案
传入color param似乎可以解决这个问题。 git diff HEAD --color = never> ; fix.patch
现在检查返回没有错误信息。
git apply fix.patch --check
改变我的.gitconfig文件
[color]
ui = always
到
[color]
ui = auto
固定我的问题,所以我不必在传递到补丁文件时通过颜色选项。
更新:基于saurabheights答案,您甚至不需要 brew链接gnu-sed
,你可以用珍珠来做到这一点。这将从不良补丁文件中移除颜色字符。可能有很多方法可以做到这一点。
perl -pe's / \x1b。*?[mGKH] // g'bad.patch> good.patch
I'm running Mac OSX 10.9.4 (Mavericks) and have git version 2.8.2. I've tested this with a completely new repo. Here's example.
mkdir gitest
cd gitest
git init
echo "monkeyface" > monkey.txt
git commit -m "first commit"
echo "monkeyface farted" > monkeyfart.txt
git add .
git diff HEAD > new.patch
rm monkeyfart.txt
git reset --hard HEAD
git apply new.patch --check
>fatal: unrecognized input
Any ideas what is causing this? Could it be anything in my .gitconfig file?
[user]
name = myusername
email = [email protected]
[color]
ui = always
[alias]
st = status -sb -uall
lg = log --decorate --pretty=oneline --abbrev-commit --graph
undocommit = reset --soft HEAD^
undopush = push -f origin HEAD^:master
[core]
editor = vim
excludesfile = ~/.gitignore_global
pager = less -r
[commit]
template = ~/.gitmessage.txt
[filter "media"]
clean = git-media-clean %f
smudge = git-media-smudge %f
UPDATE:
While the answer linked below offers some idea on what the problem might have been, my issue was specifically hidden in my configuration since no color argument was being passed into the command. This answer is relevant but my question and answer might be helpful to others who may experience a similar issue.
Extract changes from diff file to current branch
Passing in color param seems to fix the problem.
git diff HEAD --color=never > fix.patch
And now check returns no error message.
git apply fix.patch --check
Changing my .gitconfig file
[color]
ui = always
to [color] ui = auto
Fixed my problem so I do not have to pass color option when diffing to patch file.
UPDATE: Based on saurabheights answer, you don't even need to brew link gnu-sed
, you can do this with pearl. This will removed color characters from the bad patch file as well. There are probably many ways to do this.
perl -pe 's/\x1b.*?[mGKH]//g' bad.patch > good.patch
这篇关于我创建的所有GIT补丁都是致命的:无法识别的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!