Displaying Emoji in git log
#
tl;dr: Upgrade less
to a more recent version to see emoji in git log
.
If you’ve ever seen a git commit message that included emoji, you may have noticed it doesn’t display correctly when you use git log
:
$ git log
commit bad43bf2d75cc0c75f0d2731a9c9672adfa01160
Author: Luke Francl <look@recursion.org>
Date: Sun Jun 19 09:40:49 2016 -0700
First commit! <U+1F389>
Recently, I decided to try to figure this out. The first thing I noticed is that if you set --no-pager
the emoji is displayed correctly:
$ git --no-pager log
commit bad43bf2d75cc0c75f0d2731a9c9672adfa01160
Author: Luke Francl <look@recursion.org>
Date: Sun Jun 19 09:40:49 2016 -0700
First commit! 🎉
Git’s pager defaults to less
. I tried displaying the same emoji with less
:
$ echo "🎉" | less
<U+1F389>
(END)
I found a post on Stack Overflow that said to set the LESSCHARSET environment variable to “utf-8”. However, that didn’t fix the problem:
$ echo "🎉" | LESSCHARSET=utf-8 less
<U+1F389>
(END)
Other characters work, though, like the Euro symbol used on Stack Overflow:
$ echo "€" | less
€
(END)
I don’t even need LESSCHARSET because it turns out my locale is set for UTF-8 already:
$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
This made me wonder if I could upgrade less
(or in more desperate straits, fix the code). I found the source at the less home page and noticed that the version that came installed with OS X (er, macOS) was very out of date. I had version 458 and the current version is 481. I downloaded and compiled version 481 and it was able to display emoji!
The easiest way to get less version 481 on OS X is to use homebrew’s dupes repository:
$ brew install homebrew/dupes/less
After installing, make sure you’re actually using version 481:
$ less --version
less 481 (POSIX regular expressions)
Copyright (C) 1984-2015 Mark Nudelman
You can force Bash to re-hash the location of less
by executing hash -r
, or open a new terminal.
Now, you should be able to see your log messages in their full emoji glory!