Skip to content

Instantly share code, notes, and snippets.

@jarett-lee
Last active April 12, 2023 02:31
Show Gist options
  • Save jarett-lee/fb1fa917c9d598572d4630edb887587e to your computer and use it in GitHub Desktop.
Save jarett-lee/fb1fa917c9d598572d4630edb887587e to your computer and use it in GitHub Desktop.
Use Git CLI to find folder last changed dates
title description date date-meta github-comments
Use Git CLI to find folder last changed date
Curious about which folders you've worked on recently and which folders have been gathering dust in a Git project? Use Git CLI to find the last date the folder has been changed.
April 2023
2023-04-10

I have a folder in git that contains all my projects. I wanted to find which projects I haven't worked on in a while to clean them up, so I made this command.

ls -1 projects

dnd
home-server
learn-japanese

find projects -maxdepth 1 -type d \( ! -name . \) -exec git log --pretty=format:'%ad {}' --date=format:'%Y-%m-%d' -1 {} \; -exec echo \; | sort

2019-12-05 home-server
2023-01-07 learn-japanese
2023-04-08 dnd

Explanation

find sort explainshell.com

find projects -maxdepth 1 -type d \( ! -name . \) \
  -exec git log --pretty=format:'%ad {}' --date=format:'%Y-%m-%d' -1 {} \; \
  -exec echo \; \
  | sort

git explainshell.com

  • %ad is the date
  • -1 looks at a single commit per folder
git log --pretty=format:'%ad projects/home-server' --date=format:'%Y-%m-%d' -1 projects/home-server
@jarett-lee
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment