Knowing previous commit hash in CI

I’d like to be able to summarise the commits incorporated in our CI. If I knew the git commit hash prior to the current commit, I could get the listing as such:

  before_commit=$(git rev-parse HEAD)
  if git pull | grep 'Fast-forward' >> /dev/null
  then
    git log $before_commit..HEAD --no-merges --pretty='- %s - %an (%h)'
  fi

(That snippet’s from a hacky update.sh I wrote in an older CI tool)

1 Like