Created
September 2, 2015 07:27
-
-
Save yohangdev/8d290a63e4282d511986 to your computer and use it in GitHub Desktop.
Git Pre-Commit Hooks Write Commit Hash to File
This file contains 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 | |
set -e | |
#=== 'prev-commit' solution by o_O Tync | |
#commit_hash=$(git rev-parse --verify HEAD) | |
commit=$(git log -1 --pretty="%H%n%ci") # hash \n date | |
commit_hash=$(echo "$commit" | head -1) | |
commit_date=$(echo "$commit" | head -2 | tail -1) # 2010-12-28 05:16:23 +0300 | |
branch_name=$(git symbolic-ref -q HEAD) # http://stackoverflow.com/questions/1593051/#1593487 | |
branch_name=${branch_name##refs/heads/} | |
branch_name=${branch_name:-HEAD} # 'HEAD' indicates detached HEAD situation | |
# Write it | |
echo "prev_commit='$commit_hash'\ndate='$commit_date'\nbranch='$branch'\n" > web-app/v2/version.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment