1、git apply的空白问题
$ git apply foobar.patch
foobar.patch:271: trailing whitespace.
foobar.patch:465: space before tab in indent.
.paging_full_numbers a.paginate_active {
warning: squelched 1705 whitespace errors
warning: 1710 lines add whitespace errors.
看看git apply(1)手册上怎么说:
– -whitespace=
When applying a patch, detect a new or modified line that has whitespace errors. What are considered whitespace errors is controlled by core.whitespace configuration. By default, trailing whitespaces (including lines that solely consist of whitespaces) and a space character that is immediately followed by a tab character inside the initial indent of the line are considered whitespace errors.
By default, the command outputs warning messages but applies the patch. When git-apply is used for statistics and not applying a patch, it defaults to nowarn.
You can use different values to control this behavior:
nowarn — turns off the trailing whitespace warning.
warn — outputs warnings for a few such errors, but applies the patch as-is (default).
fix — outputs warnings for a few such errors, and applies the patch after fixing them (strip is a synonym — the tool used to consider only trailing whitespace characters as errors, and the fix involved stripping them, but modern gits do more).
error — outputs warnings for a few such errors, and refuses to apply the patch.
error-all — is similar to error but shows all errors.
git apply应用补丁时会检测空白错误,默认情况下,尾部空白,包含空白的空行,初始tab缩进之后紧跟的空白字符会被认为是错误。
处理这个错误的行为由命令行参数–whitespace或者core.whitespace配置来控制,共有5种可能的动作:
nowarn
关闭错误提示
warn
输出部分错误提示,但完整的应用补丁,不会处理错误,这是默认动作。
fix
输出部分错误,修正错误后应用补丁
error
输出部分错误,拒绝应用补丁。
error-all
输出全部的错误,拒绝应用补丁。
git解决git apply时遇到trailing whitespace问题
git apply --whitespace=fix your.patch
增加 --whitespace=fix ,网上的其他方式都不好用
2、今天在打Patch的时候遇到了以下warnning:
new blank line at EOF.
+
warning: 1 line adds whitespace errors.
解决方法:
现象:
git am someone.patch
Applying: …
/workingfolder/.git/rebase-apply/patch:50: trailing whitespace.
…
warning: squelched 3 whitespace errors
warning: 6 lines applied after fixing whitespace errors.
===============================
原因:
告警的含义是提示有空格在行尾出现。
检查后的确有空格在行尾。
具体方法:
-
git reset --hard <前一个commit id>
-
git am --reject --whitespace=fix /someone.patch
-
git format-patch -01 重新制作补丁,然后利用
vimdiff检查一下,是否已修正。