简体   繁体   中英

Undo git's line ending conversion?

I have a PNG icon in my repository which got corrupt after pushing it to the remote. Using git check-attr I found out that git treats it as text file and thus converted its line endings to LF according to the repository's .gitattributes .

Is there a way to recover the original file?

Sadly it seems like that it's not possible to retrieve the original version of an " autocrlf ed" file, as long as there is no untouched version of the file in the history (means no autocrlf used).

With core.autocrlf true git replaces all occurences of the windows line ending ( \\r\\n ) with the unix style line ending ( \\n ). After that it's not possible to determine which \\n bytes used to be encoded as \\r\\n bytes.

Therefore I'm obliged to conclude that it's impossible to restore the file.

This is a reason to avoid autocrlf and to handle line endings yourself. In general I recommend to avoid autocrlf ; more information on this topic can be found here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM