Skip to content

Instantly share code, notes, and snippets.

@natenho
Created December 22, 2022 16:39
Show Gist options
  • Save natenho/dd33741d6dcb046f7c2e7f0a60d9cefc to your computer and use it in GitHub Desktop.
Save natenho/dd33741d6dcb046f7c2e7f0a60d9cefc to your computer and use it in GitHub Desktop.
Git - Get the list of modified directories from the last tag (ou last commit)
#!/bin/bash -x
# Get the last tag
last_tag=$(git describe --tags 2> /dev/null)
# If the last tag does not exist, get the commit hash of the last commit
if [ $? -ne 0 ]; then
last_tag="HEAD~1"
fi
# Get the list of modified directories
modified_dirs=$(git diff --dirstat=files,0 $last_tag HEAD | awk '{print $2}')
# Print the modified directories
echo " modified directories: $modified_dirs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment