OT - anybody good with Github and images?

Not really HA related, but as most of you know I have my configuration on Github for people to see and use and whatever, and when I first put it up I had a couple of screenshots, which I then took down as I changed my config around and so on and so forth.

Anyway, a lttle while ago I decided to put some screenshots up, added them to the folder on my local machine and pushed them to Github. Long story short, the files went, but they just appeared as ‘binary files’ so I couldn;t actually use them as screenshots, but I had a load of other stuff on so I gave up on the idea.

Tonight I decided to have a bit of a clear up on my repo and realised I still hadn’t put the screenshots back, so,seeing as I was on Github anyway I uploaded them straight there. This worked, and for all of half an hour I had some lovely screenshots on this page…

link removed

Since then I have pulled the changes back to my local machine,made some minor edits to some other files (the image files weren’t touched) and then pushed the changes. I changed 4 files, but it showed as 7 files changed, the 3 additional files being the images. And now. unsurprisingly, the images aren’t working again.

Anybody got a clue what’s going on? I’ve googled it to death before and can’t get anywhere. The images are fine on my local system, but for some reason when they go up to Github they don’t make it as images.

Any help appreciated - cheers!

Problem demonstrated here…

link removed

If you click on the earlier commit (in the file history for any of the images) you can see the screenshots, then I pulled it to local (which worked cos I can see them perfectly on the local machine), didn’t touch them at all, but next time I pushed an update, as you can see they’ve gone up as something unreadable (even though AFAICT they shouldn’t have been pushed anyway because they haven’t been edited) :confused:

I have downloaded the working and not working 2018-03-24 (1).png’s. They have different md5 checksums. As far as the content goes they’re almost exactly the same. Almost isn’t enough though. One file I can view, the other one not.

This is a vimdiff of both files:


The one on the right is the one that’s working. You see that red highlighted thing. That’s what seems to be what is missing in the broken file (which is one byte smaller).

I’ve seen that character before in text-files. In those cases it’s either the Windows-way of having new lines (\r\n) in textfiles or the unix way (\n).

Having opened both files in Notepad++ seems to agree. One file is labelled as Unix, the other was Dos/Windows.

That all being said: I don’t know why this happens and how to solve this. What I would try: push everything to GitHub, re-upload the working image, delete the repository from your harddrive, clone the repository again. Once it’s cloned get into the directory and do a git status. If the images appear as changed again, then something on your system is messing with your files.
The more sophisticated approach would be to extend your Google research with the information I have provided. That way there may be an explanation which would be good to know for others as well.

You, sir, are a genius!

I think I know what’s going on now. I have a .gitattributes file that changes the line endings to Unix on commit. Although why it would be applying that to .png files is beyond me.

Now that you’ve mentioned it, I probably added that file around about the time I removed the screenshots I had from ages ago. I’d added it as part of a cleanup because GitHub was displaying red carriage return arrows all over the place. This would explain why they worked back then but don’t now.

So, when I’ve woken up properly I’ll work out if there’s a way to strip out the windows characters from the text files, but not touch the pictures.

Thank you @danielperna84 :sunglasses::sunglasses:

/slides a beer down the bar

1 Like

Sorted it - so, just in case anybody else comes across this…

I’d slightly misread the instructions for creating a .gitattributes file and the only line in it was:

* text eol=lf

I understood that to mean “take all text files and convert their end of line characters to lf” but it actually means “all files are text, convert their line endings…”

My file now contains:

* text eol=lf
*.png -text

Which means “All files are text, convert their end of lines except png files, which aren’t text” and now everything works :sunglasses:

Thanks again for setting me on the right path @danielperna84 :+1:

2 Likes