使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 --