

Sending changes rather than results lets each contributor review what changed, decide what they want to keep or eliminate, and accurately document the process. You could iterate on my changes, generate a new patch, and send that to me for review.
LINUX COMPARE FILES PATCH
There's no limit to how many times you can patch a file. Warm a teapot in the proving drawer of your oven. Lines got added, lines got subtracted, and in the end, you end up with a file identical to my version: $ cat tea.md You apply a patch with the patch command: $ patch tea.md tea.patch Once I have a patch file, I could send it to you for you to review and, optionally, apply to your old file. Seth Kenlon, CC BY-SA 4.0) Applying changes with patch I like to view patch files in Emacs, which color-codes each line depending on whether it's gotten added or subtracted. The contents of the file are exactly the same as what was output to the terminal. You can do this using standard Bash redirection: $ diff -u tea.md tea-revised.md > tea.patch

Create a patch with diffĪ patch file is just the output of the diff -unified command placed into a file. A minus sign ( -) at the beginning of a line indicates a line that's gotten removed or changed.
LINUX COMPARE FILES PLUS
Keep it warm with a tea cosy.Ī plus sign ( +) at the beginning of a line indicates something that's gotten added to the old file. Provide diff with the old file and then the new file: $ diff -unified tea.md tea-revised.md By default, diff prints its output to the terminal.

A line that's changed in any way is treated as a line that got subtracted and then added. There are a few different ways to view the results, but I think the clearest one is the -unified ( -u for short) view, which shows which lines got added or subtracted. The diff tool displays the difference between two files. Some lines are completely new, and some lines are the same but in a different order. Keep it warm with a tea cosy.Īs expected, some items ( Boil water and Pour tea into cup) are unchanged, while other lines ( Warm the teapot) have had additions. In an effort to clarify the tea-making process, I copy the file as tea-revision.md and edit it, ending up with this: Warm a teapot in the proving drawer of your oven. It seems reasonable, but there are always optimizations you can make, so you send the file to me for improvement. So far, the file tea.md contains raw copy-paste: Boil water.
LINUX COMPARE FILES HOW TO
Suppose you and I are collaborating on a file describing how to make a cup of tea. With the diff command, you can create a record of how the file has changed, and with patch you can "replay" those changes over the old version to bring it up to date with the new version. There are so many changes that it's difficult to pick out exactly what's changed. It's difficult to replicate changes without blissfully accepting that all changes are equally valid, and replacing the old file with the new one. Some items get changed, others are left alone, new content gets added, and some stay the same but are moved to different places in the document. Free online course: RHEL Technical OverviewĮven with a simple file, there's complexity in synchronizing two documents.
