开发者

Fixing line feeds problems in git

I accidentally replaced my CRLF to LF line endings during a commit. The file history now look like this:

+---------+-----------+
| Version | Line Feed |
+---------+-----------+
|    4    | CRLF      |
|    3    | CRLF      | << changed all LFs back to CRLFs
|    2    | LF        |开发者_如何学JAVA << mistake introduced here
|    1    | CRLF      |
+---------+-----------+

The problem is that this file is now identified as a binary file (even after I have manually corrected the problem in version 3). This resulted in diff, blame and other tools to stop working as expected on this text file.

I tried setting *.xml crlf diff in ./git/info/attributes but it only works for diff not for blame, also suspecting I might face problems with merge conflicts. It also gives me LF will be replaced by CRLF warnings when committing this file, indicating that the attributes settings are not sufficient.

This is on a Windows OS with autocrlf = true set.

How do I get git to identify it as a text file again?


The 'crlf' attribute is deprecated. It has been replaced by the 'text' and 'eol' attributes, but you most likely do not need to use the 'eol' attribute.

Git was never intended to store CRLF line endings internally so this may require history rewriting to completely fix. The commits that changed the line ending will be the earliest commits that blame will see because it thinks the entire file was rewritten (it was).

One way to try and prevent this from happening again is to add * text=auto to .gitattributes and commiting that file to the repo.

More info about this can be found at the gitattributes man page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜