DEV Community

printfapps
printfapps

Posted on

Find the files you changed recently with git from the command line

You come back to a project after lunch, or after a week, and want to pick up where you left off. Which files did you actually touch?

How do you do it?

You try ls -t. It only looks at the top folder, so you get folders:

node_modules
dist
public
src
Enter fullscreen mode Exit fullscreen mode

You ask an AI, and get find . -type f | xargs ls -lt | head. The top of the list is git's own files:

./.git/HEAD
./.git/config
./.git/hooks/push-to-checkout.sample
./.git/hooks/update.sample
Enter fullscreen mode Exit fullscreen mode

You ask it to skip .git. Now the newest files are build output, a log and node_modules:

11:10 AM  dist/assets/index-4f2a9c.js             403.2 K
11:09 AM  debug.log                               2.6 M
11:08 AM  node_modules/.vite/deps/react.js        1.0 M
11:07 AM  src/components/CheckoutForm.tsx         4.6 K
Enter fullscreen mode Exit fullscreen mode

You ask again, and finally get the right idea: ask git which files it cares about (git ls-files, which respects .gitignore), then sort those by time. It takes a stat with macOS-only flags, a sort and an awk for readable sizes.

You save it somewhere: a Markdown note, or a recent.sh file. Next time it's another project, or you want 20 files instead of 10, or you want to see the build output after all, and you have to find the script and edit it.

With cmdbook, the script has one place to live, and it gets a GUI for free.

The folder, the number of files and whether to respect  raw `.gitignore` endraw  become fields of a form

Here's how

1. Save the script once. Create a command in cmdbook and paste the script (it's at the end).

2. Mark what changes. The folder, the number of files and whether to respect .gitignore become placeholders:

DIR="{{prompt:folder}}"
N="{{prompt:count?10}}"
GITIGNORE="{{prompt:gitignore?yes|no}}"
Enter fullscreen mode Exit fullscreen mode

?10 is the default. yes|no becomes a dropdown.

3. Click Run. cmdbook shows a form. Drag the project folder onto it, press Enter.

4. Read your morning.

11/16/2026 11:07 AM  src/components/CheckoutForm.tsx       4.6 K
11/16/2026 11:00 AM  src/api/orders.ts                     6.2 K
11/16/2026 10:54 AM  src/components/CheckoutForm.test.tsx  8.8 K
11/16/2026 10:45 AM  src/styles/checkout.css               2.6 K
11/16/2026 10:23 AM  docs/release-notes.md                 6.7 K
Enter fullscreen mode Exit fullscreen mode

Only your files, newest first. When you do want to see what the build wrote, switch .gitignore to no.

Next time, your last folder and count are already filled in.

That's all a script needs to get a GUI: mark the parts that change. The rest is the script you already have.

Try cmdbook here: printf.app/cmdbook

The full script (macOS)

DIR="{{prompt:folder}}"
N="{{prompt:count?10}}"
GITIGNORE="{{prompt:gitignore?yes|no}}"
T="$(printf '\t')"
cd "$DIR" || exit 1
if [ "$GITIGNORE" = yes ] && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
  git ls-files -z --cached --others --exclude-standard   # tracked + new, minus ignored
else
  find . -type f -not -path './.git/*' -print0
fi |
  xargs -0 stat -f "%m$T%Sm$T%N$T%z" -t '%m/%d/%Y %I:%M %p' 2>/dev/null |
  sort -rn | head -n "$N" |
  awk -F"$T" -v OFS="$T" '{ sub(/^\.\//, "", $3); s = $4; u = "B"
    if (s >= 1024) { s /= 1024; u = "K" }; if (s >= 1024) { s /= 1024; u = "M" }
    print $2, $3, (u == "B" ? s " B" : sprintf("%.1f %s", s, u)) }' |
  column -t -s "$T"
Enter fullscreen mode Exit fullscreen mode

On Linux, replace the stat line with xargs -0 stat -c "%Y$T%y$T%n$T%s" (the time column then shows a full timestamp).

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The git ls-files point landed for me — find dragging .git objects into the list is exactly the kind of noise that makes a recent-files list useless, and the macOS stat flag detail explains why my own version of this always looked slightly off on my machine. The default of 10 and the example output with the 4.6 K CheckoutForm.tsx make the script easy to picture using. Do you usually run this from the repo root, or have you wired it into an alias that works from any subdirectory?