git am --keep-cr 的作用

git-am 手册上说
With --keep-cr, call git mailsplit (see git-mailsplit(1)) with the same option, 
to prevent it from stripping CR at the end of lines. am.keepcr configuration 
variable can be used to specify the default behaviour. --no-keep-cr is useful 

to override am.keepcr.


git-mailsplit手册上说
--keep-cr
Do not remove \r from lines ending with \r\n.


patch文件中以\r\n结尾的行,git am默认行为会将回车符\r移除。加上--keep-cr可以防止这一默认行为,即保留回车符。

如果不加这个参数,git am可能会报错。例如

# git am  0001-test-commit-2.patch 
Applying: test commit 2
error: patch failed: tests/qemu-iotests/051.out:163
error: tests/qemu-iotests/051.out: patch does not apply
Patch failed at 0001 test commit 2
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".


该错误比较隐蔽,经过仔细比对,发现是行尾的回车符导致patch失败。此时,或者修改patch文件,或者加上-keep-cr参数。这里采用后者。

# git am --keep-cr 0001-test-commit-2.patch 
Applying: test commit 2
/tmp/root/rpmbuild/BUILD/qemu-1.5.3/.git/rebase-apply/patch:211: trailing whitespace.
QEMU 1.5.50 monitor - type 'help' for more information
/tmp/root/rpmbuild/BUILD/qemu-1.5.3/.git/rebase-apply/patch:212: trailing whitespace.
(qemu) quit
warning: 2 lines add whitespace errors.


git am执行成功。



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值