-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
- alphaFile: rhs.yaml
---
- zeta
- mu
- psi
- alpha
- gamma
- gamma
- phi
- beta
- chiBy 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 --sync-arrays (-a) 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.
This isn't the best option for every use-case. For example, this is counter-useful when the elements are time-based observations or an important sequence of specific actions.