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
    git log $before_commit..HEAD --no-merges --pretty='- %s - %an (%h)'

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

1 Like