• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Programming / Git file force as binary

Git file force as binary

Last updated on August 26, 2016 by Sal Ferrarello

Goal

Mark generated (concatenated and minified) JavaScript files and CSS files as binary files within Git to allow checking them in while avoiding merge conflicts (currently, I don’t check these files in).

Failure

I have been unable to get this to work so I thought I’d document my issue here and update this page when I have a resolution. I’m hoping someone more knowledgable than I on the topic of Git can help me understand where I’m failing.

Update 2016-08-26 I have given up on this quest and currently check in my generated JavaScript and CSS on any projects where I use Git for deployment.

My environment

  • MacBook Pro running 10.9.2 (Mavericks)
  • Git version 1.8.4
  • Using repo https://github.com/salcode/git-force-binary-test

Test if a File is Binary

Currently, I’m using the following technique to test if a file is treated as binary by Git.
git merge-file /dev/null /dev/null file-to-test from Stack Overflow How to determine if Git handles a file as binary or as text?.

Specifically, I’m using the lines
git merge-file /dev/null /dev/null 200x200.gif Result error: Cannot merge binary files: 200×200.gif
and
git merge-file /dev/null /dev/null style.min.css Result (no message, indicates NOT a binary file)

Change I’m Making

I’ve added a .gitattributes file to the repo, which includes the line style.min.css binary.
My understanding is this line should force Git to treat style.min.css as a binary file.
As per http://git-scm.com/book/en/Customizing-Git-Git-Attributes#Binary-Files

Expected Result

git merge-file /dev/null /dev/null style.min.css
Result error: Cannot merge binary files: style.min.css

Actual Result

git merge-file /dev/null /dev/null style.min.css
Result (no message, indicates NOT a binary file)

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Filed Under: Programming Tagged With: Git

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in