-
-
Notifications
You must be signed in to change notification settings - Fork 23
yaml diff Examples
This page explores various real-world use-cases for the yaml-diff command-line tool.
It is sometimes more informative to compare Arrays by the distinctiveness of their elements rather than the order of them. Consider the following differences.
File: lhs.yaml
---
- alpha
- mu
- psi
- beta
- delta
- chi
- delta
- gamma
- alpha
File: rhs.yaml
---
- zeta
- mu
- psi
- alpha
- gamma
- gamma
- phi
- beta
- chi
By default, Array element are compared by the order in which they appear. For the sample documents, this produces the following differences:
c [0]
< alpha
---
> zeta
c [3]
< beta
---
> alpha
c [4]
< delta
---
> gamma
c [5]
< chi
---
> gamma
c [6]
< delta
---
> phi
c [7]
< gamma
---
> beta
c [8]
< alpha
---
> chi
When using the --arrays=value
(-A value
) option, this output turns very different. Rather than comparing each element, one-by-one in the order they appear within both Arrays, the elements are instead rearranged to match them together as much as possible. Doing so produces this output:
d [4]
< delta
d [6]
< delta
d [8]
< alpha
a [9]
> zeta
a [10]
> gamma
a [11]
> phi
Note once the elements are synchronized, there are actually far fewer differences between the two documents. By comparing the elements by value rather than position, we can see which elements are unique between the two Arrays.