Skip to main content

knife diff

Use the knife diff subcommand to compare the differences between files and directories on the Chef Infra Server and in the chef-repo. For example, to compare files on the Chef Infra Server before uploading or downloading files using the knife download and knife upload subcommands, or to ensure that certain files in multiple production environments are the same. This subcommand is similar to the git diff command that can be used to diff what is in the chef-repo with what is synced to a git repository.


This subcommand has the following syntax:

knife diff [PATTERN...] (options)



Review the list of common options available to this (and all) knife subcommands and plugins.

This subcommand has the following options:

--chef-repo-path PATH

The path to the chef-repo. This setting will override the default path to the chef-repo. Default: same value as specified by chef_repo_path in client.rb.

--cookbook-version VERSION

The version of a cookbook to download.


The number of allowed concurrent connections. Default: 10.


Select only files that have been added (A), deleted (D), modified (M), and/or have had their type changed (T). Any combination of filter characters may be used, including no filter characters. Use * to select all paths if a file matches other criteria in the comparison. Default value: nil.


Show only the names of modified files.


Show only the names of files with a status of Added, Deleted, Modified, or Type Changed.


Use --no-recurse to disable listing a directory recursively. Default: --recurse.

--repo-mode MODE

The layout of the local chef-repo. Possible values: static, everything, or hosted_everything. Use static for just roles, environments, cookbooks, and data bags. By default, everything and hosted_everything are dynamically selected depending on the server type. Default: everything / hosted_everything.


See config.rb for more information about how to add certain knife options as settings in the config.rb file.


The following examples show how to use this knife subcommand:

Compare files that contain JSON data

To compare the base.json role to a webserver.json role, enter:

knife diff roles/base.json roles/webserver.json

Compare the chef-repo and the server

To compare the differences between the local chef-repo and the files that are on the Chef Infra Server, enter:

knife diff

Compare, then return results

To diff a node named node-lb and then only return files that have been added, deleted, modified, or changed, enter:

knife diff --name-status node-lb

to return something like:

Edit this page on GitHub

Thank you for your feedback!


Search Results