MERM
MERM

Reputation: 752

git smudge/clean filters to only act on text (not binary) files

While writing git filters for smudge & clean, I want to make sure that the filters only act on text files and not binary ones (images and the like).

Is there a way for git to tell me whether it thinks the file is binary or not? I could test the file myself, but I am not confident that I will always get the same result as git.

Upvotes: 1

Views: 336

Answers (1)

VonC
VonC

Reputation: 1326576

One cheap way is to use file extension:

If you declare your smudge/clean script in a .gitattributes file, you can associate it to a certain list/group of files, based on a filename pattern.

you can set a filter for particular paths and then set up scripts that will process files just before they’re checked out

Plus, in that same .gitattributes file, you can tell git what files are binaries or not.

In short, it is a declarative process.

Upvotes: 1

Related Questions