Git认为我每次做一个小改动都会重写我的一个文件 [英] Git thinks I am rewriting one of my files everytime I make a small change
问题描述
我有一个中等大小的Java文件。每次我对我的一个文件BuildTable.java进行更改时,Git会将其报告为一个巨大的更改,即使只有一两行。 BuildTable.java大约有200行,这个提交的改变只改变了一行。
git-diff输出:
--- a / src / BuildTable.java
+++ b / src / BuildTable.java
@@ -1 +1 @@
-import java.io.FileNotFoundException; ^ Mimport java.io.FileReader; ^ Mimport java.io.InputStreamReader; ^ Mimport java.io.PushbackReader; ^ Mimport java.util.ArrayList; ^ Mimport
\在文件结尾没有换行符
+ import java.io.FileNotFoundException; ^ Mimport java.io.FileReader; ^ Mimport java.io.InputStreamReader; ^ Mimport java.io.PushbackReader; ^ Mimport java.util。 ArrayList; ^ Mimport
\在文件结尾没有新行
提交-a
创建提交fe43985:更好的错误通知
更改了3个文件,54个插入(+),50个删除( - )
重写src / BuildTable.java(78%)
文件为二进制或其他?这是一个问题吗?如果是这样,我该如何解决这个问题?解决方案
为了解决这个问题,我不需要更改任何核心git设置,因为生成的默认行结束没有问题,只是这个特定的文件被损坏了。为了解决这个问题,我打开了vim并执行了下面的命令:
$ b
:%s / ^ M / \ r / g
请注意,要键入^ M,您必须键入ctrl-V然后按Ctrl + M。 p>
I have a medium size Java file. Everytime I make a change to one of my files, BuildTable.java, Git reports it as a massive change, even if is only a line or two. BuildTable.java is about 200 lines and the change in this commit only changed a single line.
git-diff ouputs this:
--- a/src/BuildTable.java
+++ b/src/BuildTable.java
@@ -1 +1 @@
-import java.io.FileNotFoundException;^Mimport java.io.FileReader;^Mimport java.io.InputStreamReader;^Mimport java.io.PushbackReader;^Mimport java.util.ArrayList;^Mimport
\ No newline at end of file
+import java.io.FileNotFoundException;^Mimport java.io.FileReader;^Mimport java.io.InputStreamReader;^Mimport java.io.PushbackReader;^Mimport java.util.ArrayList;^Mimport
\ No newline at end of file
After doing a git-commit -a
Created commit fe43985: better error notifications
3 files changed, 54 insertions(+), 50 deletions(-)
rewrite src/BuildTable.java (78%)
Is Git seeing this file as binary or something? Is this a problem? If it is, how do I fix this?
To fix this, I didn't need to change any of the core git settings, as the default line endings being generated were fine, it was just that this particular file was mangled. To fix it I opened vim and executed the following command
:%s/^M/\r/g
Note that to type the "^M" you have to type ctrl-V and then ctrl-M.
这篇关于Git认为我每次做一个小改动都会重写我的一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!