0

I'm trying to see which of all the files I've modified but not yet committed, were modified in the last say 2 hours.

git status shows me the list of all the modified files, but I only want to see those modified recently.

I've found this question Git show files that were changed in the last 2 days but it seems to work for committed files only.

Can this be done?

Gabriel
  • 40,504
  • 73
  • 230
  • 404

1 Answers1

2

Git does not store when a file was modified, only when it was committed. Instead, check the file's modification time on your filesystem using find.

find . -not -mmin +120 -not -path './.git/*'

-not -mmin +120 looks for files which have NOT been changed at least 120 minutes ago. -not -path './.git/*' ignores the .git directory.

This will check all files in the directory. If you just want to check the ones Git knows about, filter the list from git ls-files -m on their modification times using xargs and find.

git ls-files -m | xargs -I file find file -not -mmin +120

Or with xargs and bash.

git ls-files -m | xargs -I file bash -c '(( $(date +%s) - $(stat --printf='%Y' file) < 7200 )) && echo file'
Schwern
  • 153,029
  • 25
  • 195
  • 336