Contents

diff and patch

Record (diff) and apply (patch) changes to the source code.

Sources

Find the difference of two files

For example, I want to apply some changes to the default MAKEPKG in /etc/makepkg.conf for my AUR builds in my future machines.

I copied /etc/makepkg.conf (the system) over to ~/.makepkg.conf (the local version) and made some modification.

The the difference of these two files was made into a patch file.

1
diff -Nur /etc/makepkg.conf ~/.makepkg.conf > makepkg.patch

Apply the patch file

On the new machine, copy /etc/makepkg.conf (the system) over to ~/.makepkg.conf and apply the patch.

1
patch -u ~/.makepkg.conf -i makepkg.patch

Comparing files in two directories

1
diff -Nur working/ modified/ > mod.patch

Apply the change to other’s working code

1
patch -ruN -d working < mod.patch

You could use --dry-run option first to see if it works.