Skip to content

Instantly share code, notes, and snippets.

@nicerobot
Last active March 13, 2019 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicerobot/91f184cb9ac802b46fa13c9a8b850c31 to your computer and use it in GitHub Desktop.
Save nicerobot/91f184cb9ac802b46fa13c9a8b850c31 to your computer and use it in GitHub Desktop.
Hash tracked git files
#!/usr/bin/env bash
# Useful for, for example, versioning docker images built from subdirectories in a mono-repo.
cd ${1:-.} || exit
git ls-tree -r --name-only $(git rev-parse --symbolic-full-name --abbrev-ref HEAD) \
| while read f; do [[ -d "${f}" ]] || [[ -f "${f}" ]] && echo ${f}; done \
| sort -fd \
| tr '\n' '\0' \
| xargs -0 openssl sha1 \
| openssl sha1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment