Training Missions

Missions: Using diff and patch

Patching entire directories

Merging contributions

Your new cookbook has been a sensation on both sides of the pond. Enthusiastic chefs are trading tips on how to cook your recipes.

As the expert chef, you like to keep abreast of the changes floating around in the world of reader-contributed recipes. An enterprising American has experimented with your recipes and created a few simple modifications that make the flavor really pop.

In this step, you'll download a patch that affects more than one file, apply it to your recipe set, and answer a question to make sure you applied it properly.

Here is your mission:

  • Download this tarball and this patch to the same directory.
  • Unpack the tarball. This will create a familiar recipes directory.
  • Look at the recipes.patch file. Note the file paths in the headers.
  • Apply the patch to your recipes directory.
  • Answer the question below about the contents of the files inside.

Context in open source

Interestingly, the patch we provide here can apply against either the British or the American ("aubergine" or "eggplant") version of these recipes.

Sometimes you might have to apply a patch that affects more than one file. The patch program can tell what parts of the patch apply to what files by examining the headers, but you might need to help it out by giving the -p option to tell it how many levels of directories to ignore so it finds the correct files to patch.

How many cloves of garlic would now be required to cook both recipes in the recipes/ directory?

If you need help with this step, try clicking through these hints.

The "low" hint level is perfect if you're just confused as to what to do.

The "high" level is great if you are unfamiliar with the commands and tools you'd use.

Read the man page for patch online,

or, if you're on Linux or Mac, use the terminal command:

man patch


You can invoke patch on the downloaded file as follows:

patch -p1 < recipes.patch

That should apply the patch file. Open up recipes.patch in a text editor and read the patch file "headers". Pay special attention to the directory paths. The -p1 says to ignore up through the first "/" in the paths in the patch headers when trying to find files to patch.

Open a command prompt, and type these commands in, one at a time. You need to copy them exactly. Make sure to press enter between each one.

First, create a directory you'll work in and change into it.

	mkdir recursivepatch
	cd recursivepatch

Then, download the original collection of recipes.

	curl -0

Unpack it, but do not change into its directory.

	tar xzvf recipes.tar.gz

Now, download the patch file contributed by the "enterprising American" in this mission step:

	curl -0

Apply that patch (you can read more in the "medium" hints about how this works):

patch -p1 < recipes.patch

Now, change directory into recipes and open each of the text files in your favorite text editor. Answer the question above!