How to compare two YAML files and find what changed
YAML Compare — open the free tool →YAML runs a lot of infrastructure: Kubernetes manifests, Helm values, Docker Compose files, GitHub Actions and GitLab CI pipelines, Ansible playbooks and app settings. When something works in one environment and not in another, the fastest way to find out why is to compare the two YAML files side by side. The catch is that two files can mean the same thing and still look different, because tools write keys in different orders.
Compare two YAML files online
- Open YAML Compare.
- Paste the original YAML on the left and the changed YAML on the right, or load the files.
- If the two files list the same keys in a different order (common when one came from
kubectl get -o yamland the other from Git), tick Sort keys. If list items can be in any order (hosts, tags, allowed IPs), also tick Ignore list order. - Click Compare now. Changed lines are highlighted, with the changed words marked inside each line.
- Use Only changes to hide matching lines in long manifests, then copy or download the report for a ticket or pull request.
What Sort keys does (and doesn't do)
- The keys of every block mapping are put in alphabetical order, at every indentation level — including mappings inside list items, such as each container in a pod spec.
- List items stay in their original order, because in YAML that order is often part of the data.
- Comments move together with the key directly below them.
- Block text written with
|or>and inline values like{a: 1, b: 2}are left exactly as written. - Both text boxes are rewritten in sorted order, so paste the originals again if you want to compare them as they were.
Ignore list order when it doesn't matter
Some YAML lists are really sets: hosts in an inventory, tags, allowed IP ranges, RBAC verbs, or environment variables. Tick Ignore list order and the items of every block list (lines starting with -) are sorted on both sides by their full content, at every level, before comparing. A reshuffled list then shows no differences, while an added, removed or edited item still does. Duplicates are kept, comments move with the item below them, and inline lists like [a, b] are left as written. For lists of mappings, such as env entries with name and value, tick Sort keys too so the items line up. Leave it off for lists whose order matters, like pipeline steps or init containers.
Compare YAML in VS Code
Open both files, right-click the first one in the Explorer and choose Select for Compare, then right-click the second and choose Compare with Selected. VS Code shows a side-by-side diff. It compares text exactly as written, so keys in a different order show up as changes.
Compare YAML on the command line
- Plain diff:
diff -u old.yaml new.yamlorgit diff --no-index old.yaml new.yamlfor a quick text comparison. - Ignore key order with yq:
diff <(yq 'sort_keys(..)' old.yaml) <(yq 'sort_keys(..)' new.yaml)sorts keys recursively on both sides first (yq v4). - Structure-aware diff:
dyff between old.yaml new.yamlreports changes by path (for examplespec.replicas) instead of by line. - Kubernetes:
kubectl diff -f manifest.yamlcompares a local manifest with what is running in the cluster.
Tips for a clean YAML comparison
- Keep whitespace differences visible: in YAML a changed indentation can move a key to a different parent.
- Output from
kubectl get -o yamlincludes fields likestatus,resourceVersionandcreationTimestampthat are never in your source file. Expect them in the diff, or delete them before comparing. - Comparing a YAML file with a JSON one? Convert one format to the other first, then use JSON Compare with Sort keys.
- For XML configs use XML Compare; for scripts and source files use Code Compare.
Frequently asked questions
How do I compare two YAML files and ignore key order?
Open YAML Compare, paste both files and tick Sort keys before clicking Compare now. The keys of every mapping are sorted alphabetically on both sides, so keys that only moved do not show as changes. On the command line, yq 'sort_keys(..)' does the same before a normal diff.
Does sorting keys change the order of list items?
No. In YAML the order of list items is often meaningful (for example pipeline steps), so Sort keys only sorts mapping keys. If a list is really a set, such as hosts or tags, tick Ignore list order as well.
How do I compare YAML lists when the items are in a different order?
Tick Ignore list order in YAML Compare. Items of every block list are sorted by their full content on both sides before comparing, so only added, removed or edited items show up. On the command line, yq '(.. | select(tag == "!!seq")) |= sort' sorts lists of plain values before a normal diff.
Can I compare multi-document YAML files?
Yes. Files with several documents separated by --- are compared as a whole, and with Sort keys each document is sorted on its own.
Are my YAML files uploaded?
No. YAML Compare runs in your browser, so hostnames, internal settings and other config details stay on your machine. Still remove real secrets before sharing a downloaded report.