Compile git revision info into Haskell projects

Version on this page:
LTS Haskell 22.29:
Stackage Nightly 2024-07-19:
Latest on Hackage:

See all snapshots githash appears in

BSD-3-Clause licensed by Michael Snoyman, Adam C. Foltzer
Maintained by [email protected]
This version can be pinned in stack with:githash-,1527

Module documentation for


Build Status

Some handy Template Haskell splices for including the current git hash and branch in the code of your project. Useful for including in panic messages, --version output, or diagnostic info for more informative bug reports.

Most of the complication in the GitHash module is due to the various places the current git hash might be stored:

  1. Detached HEAD: the hash is in .git/HEAD
  2. On a branch or tag: the hash is in a file pointed to by .git/HEAD in a location like .git/refs/heads
  3. On a branch or tag but in a repository with packed refs: the hash is in .git/packed-refs

These situations all arise under normal development workflows, but there might be further scenarios that cause problems. Let me know if you run into them!


ChangeLog for githash

  • Fixed bugs; now this library’s Template Haskell functions are much more likely on recompilation to detect Git update that doesn’t affect workspace: e.g. git switch -c <new_branch> (equivalently git checkout -b <new_branch>) and git commit --amend --only. Implemented in #23.

  • Always include patchlevel and hash in git-describe output

  • Don’t let user’s configured initial branch name break tests

  • Add git tag output via git-describe

  • Add git-describe output

  • Add git-worktree support #13

  • Test suite works outside of a Git repo #12

  • Catch exceptions thrown by readCreateProcessWithExitCode to deal with missing git executable #7

  • Add tGitInfoTry and tGitInfoCwdTry

  • Add message of the most recent commit

  • Update the test suite

  • Initial release