Netlify Building from latest commit for two consecutive pushes

I’m encountering a challenge with Netlify’s build process when pushing multiple commits quickly. Our goal is to deploy only “release” commits with updated app versions, sidelining intermediary ones. However, despite using an ignore script, both commits trigger builds, and unexpectedly, both appear to reference the latest commit.

Netlify Site Name:

Why We Use the Ignore Script:

We employ a version bumping strategy where only specific “release” commits, which contain the updated app version. Our ignore script aids in this process by checking the commit message to determine if the commit is a “release” commit. Here’s a snippet of it:

const { execSync } = require("child_process");

const log = (msg) => console.log(`[ignore-script] ${msg}`);

log(`Checking if build should be ignored for commit ${process.env.COMMIT_REF}`);

const commitMsg = execSync(`git log -1 --pretty=%B ${process.env.COMMIT_REF}`)

const isReleaseCommit = commitMsg.startsWith("Release: ");

log(`Last commit message: "${commitMsg}"`);
log(`Is release commit: "${isReleaseCommit}"`);

// ... checks and process.exit(...)

Details & Screenshots:

  1. Here’s a snapshot of the two commits/deploys:
"Release: 2.1.6+4b6a7ae" # release commit
Today at 11:22 AM
Deployed in 5m 8s

"Add some logs to version bump action (#1793)" # intermediary commit
Today at 11:22 AM
Deployed in 5m 3s

The add some logs to version bump action should have the build ignored, and the Release: 2.1.6... should be built.

  1. Given my ignore script, which uses the COMMIT_REF to get the latest commit message, I was anticipating Netlify to focus on the commit with the message Release: ... and skip the other one (4b6a…). However, when I dove into the deploy log for the 4b6a, it seems to be referencing the 8d76… commit:

Given the documentation regarding Netlify’s environment variable COMMIT_REF, this variable should be pointing to the 4b6a7ae commit instead of the latest one. Or am I missing something?

I really appreciate any help you can provide.

1 Like

Hi @kaisermann,

Sorry for the delay. I’ll try to get some eyes on this thread as soon as possible.

Hi, @kaisermann. The root cause here is that the commit that triggers the build is not necessarily the commit that gets built.

When a commit to a branch triggers a build we clone refs/heads/main (assuming the branch for the deploy is main). However, if you made other commits quickly after this, refs/heads/main pointer may reference a later commit in the same branch by the time the repo is cloned.

I’ve opened a support ticket about this and shared more details there. Please feel free to reply there or here, whichever you prefer.

Hey, hrishikesh and Luke :wave: thanks for your replies!

I suspected this would be the reason. Would it be possible then to have access to an environment variable with the build that triggered the commit? If not, I would suggest adding some text to the Env Variables documentation saying that the COMMIT_REF is not necessarily the same as the commit that triggers the build.

I’m also going to paste part of the ticket answer as it can be meaningful for someone else:

I do see that the deploy information in the API does have the correct checksum but accessing the API during the build would be a far more complex workflow. There are strings that can be added to commit messages to prevent builds from running at Netlify. Those are documented here:

Manage deploys | Netlify Docs

To summarize all this, the only way to filter the builds based on commit messages would be to query the API to get details about the deploy while it is running. While possible that would be a much more complex “build ignore command” workflow.

If there are questions about the alternate workflow or anything else related to this issue, please feel free to reply here (or to the forum thread) anytime.

I decided to attempt the “query the API” suggested approach and it indeed worked :partying_face::champagne:

However, as a bit of non-solicited feedback, I do have to say that I find it somewhat odd to have the commit_ref from the API pointing to a certain commit and the commit_ref from the environment pointing to another

1:35:00 PM: [ignore-script] [debug] 
API.commit _ref: 6497b320eabc5c4bf4bac314eeecbc3c7a2f5b65
env.COMMIT_REF: 0ee727e779295fdeba3f67d688f45fad5ccbcbac

Maybe if they had different names or a more descriptive name.

The script if anyone wants it:

const { execSync } = require('child_process')

const log = (...msg) => console.log(`[ignore-script] ${msg.join(', ')}`)

const isProduction = process.env.CONTEXT === 'production'

async function fetchDeployDetails(deployId) {
  const response = await fetch(
      method: 'GET',
      headers: {
        Authorization: `Bearer ${process.env.NETLIFY_API_TOKEN}`,

  if (!response.ok) {
    throw new Error('Failed to fetch deploy details from Netlify API')

  return response.json()

async function main() {
  if (!isProduction) {
    log('Allowing non-production build')

  try {
    const deployCommitRef = await fetchDeployDetails(
    ).then((deployDetails) => deployDetails.commit_ref)

      `[debug] API.commit _ref: ${deployCommitRef} | env.COMMIT_REF: ${process.env.COMMIT_REF}`,

    const commitMsg = execSync(`git log -1 --pretty=%B ${deployCommitRef}`)

    const isReleaseCommit = commitMsg.startsWith('Release: ')

    log(`Last commit message: "${commitMsg}"`)
    log(`Is release commit: "${isReleaseCommit}"`)

    if (isReleaseCommit) {
      log('Allowing production build')
    } else {
      log("Ignoring build: The commit message doesn't start with 'Release: '")
  } catch (error) {
    log(`Error: ${error.message}`)
    process.exit(0) // Default to ignoring the build in case of an error


Thanks for coming back and sharing this with the community along with your feedback! :netliheart: