Rsync problem versions out of sync

Hello,

I have a report which I am writing as a .tex file, and I am editing from two computers (office and home laptop). I use rsync over ssh connection to synchronise between them and all the rssync commands are written in a Shell script.

#synchronise from office computer to home laptop
rsync -auzv user@host://pathtoremote directory/   /pathtolocaldirectory

#and vice versa
rsync -auzv /pathtolocaldirectory user@host://pathtoremote directory/   

I run this code, in a shell script, after finishing some part of the work at either machine.
Now, it turns out that I have edited some portion in my laptop yesterday night, and forgotten to do this synchronisation. and came to work today, and edited the same tex file. I realised the mistake , when the generated pdf showed some old content.

Now , I am stuck. If I go home and run this synchronising commnd, it will overwrite the changes I made in my laptop . Basically I have two versions of the same file.

Is there any way, automatically you can use some shell scripting to see which portions were modified in the laptop, and merge the two versions together,. I know that diff command works to find the difference between two files, but is there some better way to do it, I dont understand very clearly the output of diff, but can rsync help in this ?

I should have used some DropBox which automatically syncs, but anyways, how do I solve this ?

This is a little messier than you might hope. You can created what is called an ed script using diff, then run ed against the script. This is usually called merging files.

The reason I suggest this approach is that latex is more like a PDL than text

Howto:
Comparing and Merging Files

Thanks all for your suggestions. I ran diff command and found with the output, which lines differ. Then I manually copy pasted the changes from one file to the other, and ran diff again .

Maybe there was a simpler solution , but this is what I found most useful.