我的差异包含尾随空白 - 如何摆脱它? [英] My diff contains trailing whitespace - how to get rid of it?

查看:135
本文介绍了我的差异包含尾随空白 - 如何摆脱它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在TextWrangler中编辑一个php文件,将行结束符设置为Unix,NetBeans和vim。当我将diff保存到一个补丁并尝试应用它时,它会给出空白错误。当我输入 git diff 时,我可以在我的行尾看到 ^ M ,但是如果我手动删除它们vim,它说我的补丁文件已损坏,然后补丁根本不适用。

我使用以下命令创建补丁:



git diff> patchname.patch



我通过检出要打补丁的文件的干净版本并输入

git apply patchname.patch



如何在没有空白错误的情况下创建此修补程序?我之前创建了修补程序,从未遇到过这个问题。

解决方案

您确定这些是很难的错误吗?默认情况下,git会警告空白错误,但仍然会接受它们。如果他们是很难的错误,那么你必须改变一些设置。您可以使用 - whitespace = 标志来 git apply 来在每个调用的基础上控制它。尝试

  git apply --whitespace = warn patchname.patch 

这将强制默认行为,即警告但接受。您也可以使用 - whitespace = nowarn 完全移除警告。

控制这个的配置变量是 apply.whitespace






对你的补丁没有错误。这是一种代码风格的东西,默认情况下git会在应用补丁时抱怨。值得注意的是,它不喜欢尾随空格。同样, git diff 会突出显示空白错误(如果您要输出到终端并且颜色处于打开状态)。默认行为是警告,但无论如何接受补丁,因为并不是每个项目都是空白的狂热。


I've tried editing a php file in TextWrangler with line endings set to Unix, in NetBeans, and in vim. When I save the diff to a patch and then try to apply it, it gives whitespace errors. When I type git diff I can see ^M at the ends of my lines, but if I manually remove these in vim, it says my patch file is corrupted, and then the patch doesn't apply at all.

I create a patch with the following command:

git diff > patchname.patch

And I apply it by checking out a clean version of the file to be patched and typing

git apply patchname.patch

How can I create this patch without whitespace errors? I've created patches before and never run into this issue.

解决方案

Are you sure those are hard errors? By default, git will warn about whitespace errors, but will still accept them. If they are hard errors then you must have changed some settings. You can use the --whitespace= flag to git apply to control this on a per-invocation basis. Try

git apply --whitespace=warn patchname.patch

That will force the default behavior, which is to warn but accept. You can also use --whitespace=nowarn to remove the warnings entirely.

The config variable that controls this is apply.whitespace.


For reference, the whitespace errors here aren't errors with your patch. It's a code style thing that git will, by default, complain about when applying patches. Notably, it dislikes trailing whitespace. Similarly git diff will highlight whitespace errors (if you're outputting to a terminal and color is on). The default behavior is to warn, but accept the patch anyway, because not every project is fanatical about whitespace.

这篇关于我的差异包含尾随空白 - 如何摆脱它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆