git_get_short_hash
This script will return the short hash of the HEAD commit of the checked out branch of the given Git repository directory ($PWD
if not given).
The suffix -dirty
will be appended if the working tree is dirty.
The length of the hash can be configured via the optional second parameter (range: [4, 40] for SHA-1 object names or [4, 64] for SHA-256 object names); the default is determined by the core.abbrev
Git configuration variable.
To get a consistent hash length across systems you should either
|
Usage
$ scripts/git/git_get_short_hash.sh
844881d
$ scripts/git/git_get_short_hash.sh path/to/git/repository
dbd0ffb
$ scripts/git/git_get_short_hash.sh . 10
844881d148
$ git config --local core.abbrev 20
$ scripts/git/git_get_short_hash.sh
844881d148be35d7c0a9
$ touch a
$ scripts/git/git_get_short_hash.sh
844881d-dirty