Guide · How-to

How to compare two YAML files and spot indentation changes

In YAML, indentation is part of the meaning. Here is how to compare config files without hiding the changes that matter.

The short version

  1. Paste the two YAML filesOriginal on the left, changed version on the right.
  2. Leave indentation visibleFor YAML, only trailing whitespace is ignored when you switch on Ignore trailing space, so indentation changes still show.
  3. Look at moved lines firstA line that moved to a different indentation level may now belong to a different parent key.
  4. Confirm with your own toolingA diff shows what changed, not whether the YAML is valid. Run your usual linter or deploy dry run afterwards.

YAML is popular for configuration (Docker Compose, Kubernetes manifests, CI pipelines) because it is easy to read. It is also easy to break: a value indented by two extra spaces can silently become a child of a different key.

Why indentation is the real change

In most languages, extra whitespace is cosmetic. In YAML it is structure. Compare these two snippets:

service:
  name: api
  port: 8080
service:
  name: api
port: 8080

They differ by two spaces on one line, yet in the second one port is no longer part of service. A comparison that ignored indentation would call them identical.

Compare without hiding indentation

Paste both files into the editor. For YAML, the Ignore trailing space option removes only spaces at the end of lines, which are invisible and never meaningful, and leaves the indentation at the start of each line alone.

What to look for in the result

  1. Moved lines. The same text on a different indentation level is a structural change, not a formatting one.
  2. Changed values. Version numbers, image tags and ports are the usual suspects in a deployment config.
  3. Added or removed keys. Check that nothing was deleted by accident when a block was copied.
  4. Tabs. YAML does not allow tab characters for indentation. A tab that sneaks in will show as a changed line.

Keep a habit of checking before you deploy

A diff tells you what changed, not whether the result is valid or does what you want. Use it as the review step, then run your normal validation (a linter, a dry run, or your CI) before the file goes anywhere that matters.

Questions

Why can't I ignore all whitespace for YAML?

Because the indentation decides which key a value belongs to. Two files that differ only in indentation can describe different data, so the YAML comparison only ignores trailing spaces.

Do tabs work in YAML?

No. YAML forbids tab characters for indentation, so a tab at the start of a line is itself a likely bug to look for in the diff.

Was this helpful?