Skip to content

Instantly share code, notes, and snippets.

@KamilSzot
Created April 25, 2014 13:51
Show Gist options
  • Save KamilSzot/11290301 to your computer and use it in GitHub Desktop.
Save KamilSzot/11290301 to your computer and use it in GitHub Desktop.
$ cat .git/hooks/pre-commit
#!/bin/bash
root_dir=`git rev-parse --show-toplevel`
for new_file in `git status --porcelain | awk '/\?\?/ { print $2 }'`;
do
echo -n "$new_file ... (i)gnore, (s)kip, (a)dd [default] ? "
read add_or_ignore < /dev/tty
echo -en "\033[1A\033[2K" > /dev/tty
if [ "$add_or_ignore" == "i" ]
then
echo "$new_file ... ignored from now on (to undo remove it from "`git rev-parse --git-dir`/info/exclude")"
echo $new_file >> `git rev-parse --git-dir`/info/exclude
else
if [ "$add_or_ignore" == "s" ]
then
echo "$new_file ... skipped (you'll be asked on next commit again)"
else
echo "$new_file ... added to repo"
git add $root_dir/$new_file
fi
fi
done
echo
@KamilSzot
Copy link
Author

Pre-commit hook that forces you to either add new files to repo or to locally ignored files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment