David Talmage writes: > I'd like to insert the git hash of HEAD in the org-mode documents that I > export. Is there an easy way? I'm exporting to LaTeX.
[] Hello, maybe you can start with a simple: #+NAME: hash-from-lisp #+BEGIN_SRC emacs-lisp (shell-command-to-string "git rev-parse HEAD" ) #+END_SRC #+RESULTS: hash-from-lisp : 099b6ceee7264832b8e13f1156974b8017e6e4bb You can hide the result using proper headers or the noexport tag and then print the result in a verbose way: The latest commit hash is src_emacs-lisp[:var i=hash-from-lisp]{(format "%s" i)} or if you enable the shell in babel you can start with: #+NAME: hash-from-shell #+BEGIN_SRC shell git rev-parse HEAD #+END_SRC For latex only, I use the following snippets. This works with gitinfo2 (in debian you need the packages texlive-latex-extra and texlive-latex-extra-doc). Sorry for the long lines... Please note that this will also highlight the dirty status of the repo, since adding the latest hash for a modified version make little sense. Best, Daniele #+LATEX_HEADER: \usepackage[,missing={Unknown},dirty={-- Uncommited Changes!!!},notags={Unknown},mark]{gitinfo2} #+LATEX: \renewcommand{\gitMarkPref}{Historical Info} # NOTE: \gitTags does not work well: it adds a traling ")" # NOTE: \gitReln takes the latest release, even there are more commits #+LATEX: \renewcommand{\gitMark}{Version:\space{}\gitTags{}\space{}--\space{}Id::\space{}\gitAbbrevHash\space{}--\space{}Date:\space{}\gitAuthorIsoDate\space{}\gitDirty} #+BEGIN_SRC emacs-lisp (defun update-gitinfo (backend) "Update .git/gitHeadInfo.gin" (message "Command: %s" (shell-command-to-string "cd `git rev-parse --show-toplevel` && /bin/bash /usr/share/doc/texlive-doc/latex/gitinfo2/post-xxx-sample.txt")) (message "Updated gitinfo")) (add-hook 'org-export-before-processing-hook #'update-gitinfo) #+END_SRC