Label differences when working with Git

Florian PircherFlorian Pircher Posts: 173
edited November 2020 in Type Design Software
Hello everyone, I’m Florian and this is my first post on TypeDrawers.

I suspect some of you are using Git to version control your source files. Git can label code-differences for many programming languages (Python, C, Java, …), but it has no built-in support for font-editing software. The labels of a Git diff are 
not particularly helpful. (I use Glyphs in the following examples, but the technique can be adapted to fit any font-editor.)

Git shows some changed nodes, but not which glyphs these nodes belong to. Teaching Git about the .glyphs-format results in this output:

Now the differences are labeled with the name of the glyph, making it much easier to review changes.

Teaching Git about a file-format involves the following two steps:

1. Open the gitattributes file. On macOS, this file is placed at ~/.config/git/attributes (e.g. /Users/Florian/.config/git/attributes). See the Git documentation for other systems. (Create folders as needed and create the file if it does not already exist.) Add the following line to the file:
*.glyphs   diff=glyphs
This tells Git to use the “glyphs”-difference for any file ending in “.glyphs”. Now you have to define the “glyphs”-difference.

2. Open the gitconfig file. This file should be placed in your home directory, e.g. /Users/Florian/.gitconfig on macOS. Create it, if it does not already exist. Add the following two lines:[diff "glyphs"] xfuncname = "^(glyphname = .*|\"@MMK.*\\{)$"Here we define the “glyphs”-difference. The important part is the value of xfuncname. It is a regular expression, which matches a line inside the .glyphs-file. I wrote a regular expression which matches two patterns (separated by “|”):
  • glyphname = .* — This matches a glyph-name (as shown in the screenshot above).
  • \"@MMK.*\\{ — This matches the beginning of a kerning-block. Compare the following Git outputs:
Without custom glyphs-difference:

With custom glyphs-difference:

In the above screenshots, I have used the GUI-application Tower, but it works on the command line as well:

Steps 1 and 2 can be applied to any file-format, not just .glyphs files. The main thing you have to change is the xfuncname, which requires a different regular expression for different file-formats. (Some formats might not even need this, UFO for example already splits glyphs into separate files.)

For more information check out the Git documentation, especially the section 
Defining a custom hunk-header. Note the terminology:


Sign In or Register to comment.