diff creates patch
In simple terms, the
diff command is used to compare differences between two versions of a file. The resulting file is called a patch, and typically is given (by the user) a ".patch" or ".diff" suffix.
This patch file then can be used on other copies of the "old" file by using the
patch command, thus updating their "old" file(s) to match the "new" file(s).
See HOW TO: Apply patches for more on applying patches.
Why you would use diff
When might one use
diff to create a patch file? Let's say you are customizing a module to fix a bug, and have saved a new version of the module. How will you pass on your bug fix to others? Simply passing on your version of the module may not work, because it's quite possible someone else has modified some other aspect of the code at the same time and you both would be overwriting each others' changes.
So instead, what you do is run
diff between the two files, and then upload the resulting patch -- which others can then apply to their files using the
patch command. (And you can apply other people's patches against your files, without losing your own changes.)
The added benefit of this type of workflow is that changes to the code can easily be tracked -- and undone, if necessary -- which is essential in a community-developed project such as Drupal.
The tools at your fingertips
The ability to create patches using
diff -- and to apply patches to your files using
patch -- is already in most computer systems. Follow the relevant links in this section to learn more about using these powerful-yet-simple commands on your platform.