Label differences when working with Git
Florian Pircher
Posts: 176
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:
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:
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:
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=glyphsThis 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:
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:
Tagged:
7
Comments
-
Very nice! For Glyphs specifically there’s also CommitGlyphs (https://glyphsapp.com/tools/commitglyphs) but I haven’t really used it.0
-
This looks great. Thanks.
But I didn't get it to work, yet. Different installation and install path, I suppose. I’ll have a look later.0 -
Florian, welcome to TypeDrawers!! This is a great tip, thanks for sharing it!0
Categories
- All Categories
- 43 Introductions
- 3.7K Typeface Design
- 801 Font Technology
- 1K Technique and Theory
- 618 Type Business
- 444 Type Design Critiques
- 542 Type Design Software
- 30 Punchcutting
- 136 Lettering and Calligraphy
- 83 Technique and Theory
- 53 Lettering Critiques
- 483 Typography
- 301 History of Typography
- 114 Education
- 68 Resources
- 499 Announcements
- 80 Events
- 105 Job Postings
- 148 Type Releases
- 165 Miscellaneous News
- 269 About TypeDrawers
- 53 TypeDrawers Announcements
- 116 Suggestions and Bug Reports