[Ilugc] .a-tip-a-day (diff - differences between text files line by line)

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Tue Sep 29 06:36:03 2009

$ diff file.txt file-modified.txt
4c4
< You are going to have a new love affair.
---

Another cookie here


$ cat file.txt
Patch griefs with proverbs.
                -- William Shakespeare, "Much Ado About Nothing"
Among the lucky, you are the chosen one.
You are going to have a new love affair.

$cat file-modified.txt
Patch griefs with proverbs.
                -- William Shakespeare, "Much Ado About Nothing"
Among the lucky, you are the chosen one.
Another cookie here


You get it? No?

diff(1) tells you how file.txt should change to become file-modified.txt

The line number is the first field in '4c4'.

c - change
a - add
d -delete

Most of the time it will get your head in a tizzy.

But never worry!

Patch will understand it. I will talk about the funny program by Larry
Wall as complicated
and meaningless as perl itself ;) later.

patch(1) loves the unified diff produced by diff -u. This is the
default svn diff format.

With cvs you have to explicitly give this.

$ cvs diff -u foo.c

will diff with the version in your working area and the repository.

And hackers also love unified diff. Instead of using '<' and '>' for
showing lines in first
file and second file respectively, '-' and '+' are used in unified
diff. Also a context is used
to say what lines precede the changes.

Nowadays you have diff between 3 files, comm and so on.

And vimdiff is a utility to merge two files.

So if you want to send patches upstream you should know a thing or two
about diff and patch.

We will look at patch(1) tomorrow.

-Girish
-- 
Gayatri Hitech
web: http://gayatri-hitech.com

SpamCheetah Spam filter:
http://spam-cheetah.com

Other related posts: