Creating a patch file from a diff of 2 folders

karatchov picture karatchov · Mar 17, 2010 · Viewed 41.9k times · Source

I made some changes to an open source project without taking time to create proper patch files.

Now, the maintainer of the project released a new version, and among new and edited files, there are a bunch of renamed files.

Whats is the best way to apply my changes to the new version ?
I'm completely new to diff/patch use, and If I can get it done with git, it would be better.

Answer

William Pursell picture William Pursell · Mar 17, 2010

If you have two directories a and b that are similar, and you want b to be the same as a, you can create and apply a patch with:

$ diff -ur b a > ba.diff
$ patch -i ba.diff

Suppose you have directories local (containing your local version of upstream1.0), upstream1.0, and upstream1.1. To create and apply your changes to upstream1.1:

$ diff -ur upstream1.0 local > my.diff
$ cd upstream1.1
$ patch -i ../my.diff 

Check the documentation for patch, and try to convince the upstream maintainers to use git. Things will be much simpler if you can use git tools to work with your local repository.