Menu

1 / 9

Git diff --quiet in CI: don't treat a missing ref as a change

DEV Community: cicd·Pobiru·about 17 hours ago
#LFIh65pk
#devtocicd#devto#dev#comparison#file
Long article (2049 words) — no AI summary yet.
Reading 0:00
15s threshold

I made a two-commit repository with one setting: the first commit sets the port to 8000 and the second changes it to 8001. In a depth-one clone, a check against the first commit could not read that revision. A two-way shell branch made it look as though Git had found a change. Git had not compared the two versions at all.

If your check can report both “different” and “couldn't compare,” an else that handles both as “different” is the bug. This matters whether the next step rebuilds an expensive artifact or decides that a check may safely be skipped.

Three outcomes for the tracked Git revision comparison: unchanged, changed, or a check error.

Save the status before running anything else

Here is a Bash gate that compares two revision arguments. The variable assignment in the else branch is the first command there, so it captures the status of Git, not of a later log line.

if git diff --quiet "$base" "$head" -- ; then printf 'No tracked changes between the selected revisions.\n' else status = $?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.