Skip to content

Latest commit

 

History

History
13 lines (11 loc) · 292 Bytes

a-shell-script-to-get-current-commit-hash.md

File metadata and controls

13 lines (11 loc) · 292 Bytes

用 shell 脚本查询 git commit hash

# ROOT_DIR is the directory contains the `.git` folder
ROOT_DIR=.
HEAD=$(cat "$ROOT_DIR"/.git/HEAD)
COMMIT=$HEAD
while [ "$COMMIT" != "${COMMIT#ref: }" ]; do
  COMMIT="$(cat "$ROOT_DIR"/.git/"${COMMIT#ref: }")"
done

echo "COMMIT=$COMMIT"