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.