使Git“LF将被CRLF替换”警告消失 [英] Make Git "LF will be replaced by CRLF" warnings go away

查看:866
本文介绍了使Git“LF将被CRLF替换”警告消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了Git,所以它不会提交不一致的行尾。与此相关的问题是整个文件堆出现,即使它们不是。

I have setup Git so it doesn't commit inconsistent line endings. The problem with that is a whole pile of files appear modified even though they are not. What do I type to make these files have the line endings fixed on the local side?

# git checkout dev
M   src/au/policy/dao/EmailQueue.java
M   src/au/policy/dao/EmailQueueFactory.java
M   src/au/policy/dao/PolicyPublisher.java
Already on 'dev'

# git diff
warning: LF will be replaced by CRLF in src/au/policy/dao/EmailQueue.java
warning: LF will be replaced by CRLF in src/au/policy/dao/EmailQueueFactory.java
warning: LF will be replaced by CRLF in src/au/policy/dao/PolicyPublisher.java

这就是我添加到我的git配置文件中的情况,这似乎是做了我打算从这个问题中排除的:

This is what I added to my git config file which seems to do what I intended aside from this issue:

autocrlf = true


推荐答案

rm <files>
git checkout -- <files>

或者,如果它们是唯一修改过的文件(注意此命令),您可以编写它像这样:

Or, if they are the only modified files (be careful with this command), you can script it like this:

git diff --name-only --diff-filter=M | xargs rm --
git checkout -- .

在GNU系统上,您可以使用稍安全的管道,但您似乎没有空间或其他分隔字符在任何情况下。

On a GNU system you can use a slightly safer pipe, but you don't appear to have spaces or other delimiting characters in your filenames in any case.

git diff -z --name-only --diff-filter=M | xargs -0 rm --

这篇关于使Git“LF将被CRLF替换”警告消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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