Created
July 20, 2012 02:03
-
-
Save foca/3148204 to your computer and use it in GitHub Desktop.
Git hook to detect if a file changed after a checkout/merge/rebase and show the diff.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Install into: | |
# - .git/hooks/post-merge | |
# - .git/hooks/post-rewrite | |
# - .git/hooks/post-checkout | |
# | |
# And make sure all are executable. | |
# | |
# Then change the $file appropriately. Enjoy. | |
file=".env.sample" | |
non-sample-file() { | |
echo $1 | sed "s/.sample//g" | |
} | |
if [[ $(git diff HEAD@{1}..HEAD@{0} -- "${file}" | wc -l) -gt 0 ]]; then | |
echo | |
echo -e "======> The file \e[33;1m${file}\e[0m changed!" | |
echo | |
git diff --color HEAD@{1}..HEAD@{0} -- "${file}" | sed 's/^/ /' | tail -n+5 | |
echo | |
echo -e " Make sure to update your \e[33;1m$(non-sample-file $file)\e[0m." | |
fi |
Super useful, thanks.
Thanks! Here is an alternative I made specifically for the West manifest file: https://gist.github.com/tomi-font/e548c23c7d9a321d452dde9c4cc43fa4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, I needed this 👍