Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell git that a text file is actually binary

Tags:

git

I committed a few PDF files into a git repository and it looks like git treated it as text and not binary. So what's in the repo is almost 1k larger than the source and no longer displays correctly.

I updated my .gitattributes file to include PDF files as binary, but the damage already seems to be done on the files in the repo. Is there any way to tell git to re-add the PDFs as binary? Would be best solution be to remove the files from the repo and re-add them?

like image 663
Andorbal Avatar asked Feb 14 '13 20:02

Andorbal


People also ask

How can you tell if a file is binary or text?

File extensions We can usually tell if a file is binary or text based on its file extension. This is because by convention the extension reflects the file format, and it is ultimately the file format that dictates whether the file data is binary or text.

Why does git think my .SQL file is a binary file?

This occurs because: SQL files contain a Byte Order Mark (BOM), this is the 0xFEFF sequence you're seeing at the start of the file. Unfortunately these bytes means git treats the file as binary, not text, and so any operations that depend on git, such as generating a diff, aren't going to return what you expect.

Does Git work with binary files?

Git LFS is a Git extension used to manage large files and binary files in a separate Git repository. Most projects today have both code and binary assets. And storing large binary files in Git repositories can be a bottleneck for Git users. That's why some Git users add Git Large File Storage (LFS).

Is txt a binary?

txt is created and the mode set to bw so that bytes can be written into the file, making it a binary file.


1 Answers

yes, remove and add back should work.

Committing a new version on top after you've added the .gitattributes file should be enough. The removing step should not be required.

like image 187
Pascal Belloncle Avatar answered Oct 21 '22 08:10

Pascal Belloncle