Quentin Del
Quentin Del

Reputation: 1685

Order git repositories based on the last commit date

I have a folder with git repositories in each subfolder

folder
./repo1    // last commit 1 week ago
./repo2    // last commit 1 day ago
./repo3    // last commit 1 month ago

I would like to rank the repositories based on the date of the last commit to see the most recent modified repositories

result

repo2
repo1
repo3

How shall I do that please ? Thanks a lot

Upvotes: 0

Views: 370

Answers (1)

Quentin
Quentin

Reputation: 63124

for repository in ./*/; do
    git -C "$repository" --no-pager log -1 --all --format="%at $(basename $repository)" 2>/dev/null;
done | sort -r | cut -d' ' -f2-

This loops over repositories, using git log to retrieve the last commit timestamp and producing output in this form:

571228806 repo1
571043015 repo2
570539599 repo3
...

The list is then sorted in reverse and cut to remove the timestamps. Note that you can output more information about the last commit from each repository by altering the format string passed to git log.

Upvotes: 1

Related Questions