-1

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.

sameer pradhan
  • 324
  • 1
  • 4
  • 14

1 Answers1

2

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

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • What if some dir are nested and repository respectively? Actually some sub dir inside ABC are nested dir and are repository too. – sameer pradhan Sep 22 '20 at 08:08