git 打补丁遇见的错误

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.

===============================
原因:
告警的含义是提示有空格在行尾出现。

检查后的确有空格在行尾。

具体方法:

  1. git reset --hard <前一个commit id>

  2. git am --reject --whitespace=fix /someone.patch

  3. git format-patch -01 重新制作补丁,然后利用

vimdiff检查一下,是否已修正。

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值