https://github.com/sters/yaml-diff
Make a diff between 2 yaml files.
https://github.com/sters/yaml-diff
diff golang yaml
Last synced: 4 months ago
JSON representation
Make a diff between 2 yaml files.
- Host: GitHub
- URL: https://github.com/sters/yaml-diff
- Owner: sters
- License: mit
- Created: 2020-06-29T03:02:22.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-07T12:58:36.000Z (about 1 year ago)
- Last Synced: 2025-04-07T13:41:12.603Z (about 1 year ago)
- Topics: diff, golang, yaml
- Language: Go
- Homepage:
- Size: 389 KB
- Stars: 38
- Watchers: 1
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yaml-diff
[](https://github.com/sters/yaml-diff/actions?query=workflow%3AGo)
[](https://codecov.io/gh/sters/yaml-diff)
[](https://goreportcard.com/report/github.com/sters/yaml-diff)
## Deprecated
I'm no longer maintein this repo. Instead, I'm creating an another tool which is more generic version of yaml-diff. Please see this repo.
https://github.com/sters/diffnest
---
## Usage
```
go install github.com/sters/yaml-diff/cmd/yaml-diff@latest
```
or download from [Releases](https://github.com/sters/yaml-diff/releases).
```
yaml-diff path/to/foo.yaml path/to/bar.yaml
```
If the given yaml has a [`---` separated structure](https://yaml.org/spec/1.2.2/#22-structures), then the two yaml's will get all the differences in their respective structures. The one with the smallest difference is considered to be the same structure and the difference is displayed.
The result structure is the same as based or target yaml but format (includes map fields order) is different.
## Example
You can try example directory.
```text
$ go run cmd/yaml-diff/main.go example/a.yaml example/b.yaml
--- example/a.yaml
+++ example/b.yaml
apiVersion: "v1"
kind: "Service"
metadata:
name: "my-service"
spec:
selector:
app: "MyApp"
ports:
-
protocol: "TCP"
- port: 80
+ port: 8080
targetPort: 9376
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
name: "app-deployment"
labels:
app: "MyApp"
spec:
- replicas: 3
+ replicas: 10
selector:
matchLabels:
app: "MyApp"
template:
metadata:
labels:
app: "MyApp"
spec:
containers:
-
name: "app"
- image: "my-app:1.0.0"
+ image: "my-app:1.1.0"
ports:
-
containerPort: 9376
- foo: "missing-in-b"
this:
is:
the: "same"
- empty:
+ bar:
+ - "missing in a.yaml"
+ baz:
+ - "missing in a.yaml"
```
```text
$ go run cmd/yaml-diff/main.go --ignore-empty-fields example/a.yaml example/b.yaml
--- example/a.yaml
+++ example/b.yaml
apiVersion: "v1"
kind: "Service"
metadata:
name: "my-service"
spec:
selector:
app: "MyApp"
ports:
-
protocol: "TCP"
- port: 80
+ port: 8080
targetPort: 9376
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
name: "app-deployment"
labels:
app: "MyApp"
spec:
- replicas: 3
+ replicas: 10
selector:
matchLabels:
app: "MyApp"
template:
metadata:
labels:
app: "MyApp"
spec:
containers:
-
name: "app"
- image: "my-app:1.0.0"
+ image: "my-app:1.1.0"
ports:
-
containerPort: 9376
- foo: "missing-in-b"
this:
is:
the: "same"
empty:
+ bar:
+ - "missing in a.yaml"
+ baz:
+ - "missing in a.yaml"
```