Let's say the directory name ABC is my project which is not a git repository. Inside that dir ABC i have many directories which are git repository respectively. And i want every git repository's commit id of their heads with a single command (repo or git command) or script.
Thanks in advance.
In Bash,
find ABC -name .git | awk '{
cmd = "GIT_DIR="$NF" git rev-parse HEAD"
while ( ( cmd | getline result ) > 0 ) {
print $NF, result
}
close(cmd)
}'
The script iterates all .git
under ABC
, assuming that they are all git repositories, runs git rev-parse HEAD
in each to get the head commit, and prints the repository folders and the SHA1 values.
Reference: https://stackoverflow.com/a/55278818/6330106