You can teach an old git new tricks...
- Save each file with the same name as in the gist (for instance,
pre-commit) - Make it executable:
chmod +x pre-commit - Put it in the
.git/hooksdirectory of a git project
| #!/bin/bash | |
| # git hook to show the last commit every time you switch branches | |
| # Run `chmod +x post-checkout` to make it executable then put it into `.git/hooks/`. | |
| set -e | |
| prevHEAD=$1 | |
| newHEAD=$2 | |
| checkoutType=$3 | |
| [[ $checkoutType == 1 ]] && checkoutType='branch' || checkoutType='file' ; | |
| if [[ $checkoutType == 'branch' ]]; then | |
| echo 'Last commit: '`git log -n 1 --oneline --color $newHEAD` | |
| fi |
| #!/bin/bash | |
| # Based on https://gist.github.com/sindresorhus/7996717 by Sindre Sorhus | |
| # git hook to notify if an important file has changed after `git pull` | |
| # Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`. | |
| changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | |
| notify_change() { | |
| echo "$changed_files" | grep --quiet "$1" && echo "$1 has changed, you may need to run \`$2\`" | |
| } | |
| # Notify if package.json or bower.json has changed | |
| notify_change package.json "npm install" | |
| notify_change bower.json "bower install" |
| #!/bin/sh | |
| # git hook to run `npm test` each time you commit | |
| # If tests fail, the commit will be aborted (can be skipped using `--no-verify`) | |
| # Run `chmod +x pre-commit` to make it executable then put it into `.git/hooks/`. | |
| npm test |