Skip to content

Instantly share code, notes, and snippets.

@nschneid nschneid/pre-commit
Created Apr 26, 2015

What would you like to do?
Prevent git commits that miss files included in a LaTeX project
# Git pre-commit hook to look for untracked files mentioned in the LaTeX and BibTeX logs.
# Fail if any are found. Note that this is not foolproof, as included .tex files
# not generating any errors or warnings may not be mentioned in the log.
# Goes in file .git/hooks/pre-commit under the repository root.
# Nathan Schneider (, 2015-02-26
# Adapted from
. git-sh-setup # for 'die' cmd
git status --porcelain | while IFS= read -r line;
if [[ $line == \?\?* ]] ; then # if the file begins with ?? it's untracked by git
if [[ `fgrep "/$fname" tmp/*.log` || `fgrep "$fname" tmp/*.blg` ]] ; then
die "Uncommited files left! $fname" # this will always terminate commit
# say "Uncommited files left!" # this will just print the warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.