Sunday, February 14, 2010

27. What is difference between Diff and Patch

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" 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).
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.

No comments:

Post a Comment