How to Get a List of Directories with Updated Files Since the Last Git Merge

Git
Linux
Using Linux commands to get a list of recently changed files and parse out the root directories.
Author

Ziyue Li

Published

December 12, 2022

It’s as simple as the following:

folders=$(git diff --name-only HEAD@{1}..HEAD | awk -F/ '{print $1}' | uniq)

git diff gets all files that have changed, awk -F/ parses out the directory name before the first /, and finally uniq returns a list of unique directory names.