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执行成功。