Get list of commits in build



For every build I see at the top the new commits that were added. Is there a way to get a reference to the commits via a git command?
My goal is make a script to check if there were changes in a certain directory in a build and if yes, send a Slack notification. The script should work with merge commits and also with rebased commits.

Any ideas? Thanks a lot!

Commit range environment variable
CIRCLE_COMPARE_URL is empty when running a workflow job

This seems to work:

# Extract commit range (or single commit)
COMMIT_RANGE=$(echo "${CIRCLE_COMPARE_URL}" | cut -d/ -f7)

# Fix single commit, unfortunately we don't always get a commit range from Circle CI
if [[ $COMMIT_RANGE != *"..."* ]]; then