I need to apply some code changes to a source code file I don't have access to. I write code but rely on someone else to test it for me because my old computer has trouble with VMs. Most of the changes are fixing small syntax errors, but I think there were some code instertions, some newlines, etc. I've never used diff in this way before. And I've never used patch ever. Is this possible?

Recommended Answers

All 4 Replies

diff is used to find the differences between two files. So you will need a copy of the file before the changes were made and a copy of the file after the changes were made.

in other words no. Thats OK. I noticed diff worked by identifying line numbers where files differed I hoped that if perhaps the files had the same number of lines, changes could still be made. But I also noticed there are different versions of a diff file.

There has to be two versions of the file so that diff can tell you the differences. How would you expect diff to work with only 1 file??? The two files don't have to have the same number of lines, at least not with the diff pogram I've used in MS-Windows.

Depending upon how you use it, diff can generate files that the patch command can use to update a source file by merging the deltas between the two versions. You need to read the man pages for diff and patch in detail in order to understand how that works, and whether it is applicable for your needs. This technique is commonly used when distribution source code patches for Linux system software, so there is abundant information on the web that can help. Remember, Google (or DuckDuckGo) is your friend! :-)

In any case, if you get the original version of a source file and edit it, you can use diff to generate the deltas that the patch command can be used to create a new (and hopefully fixed) source file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.