Thursday 2 June 2011

Using the GNU diff tool to make patch files from exported repository directories

I had a working copy from a repository I didn't want to directly modify (as I don't want to waste bandwidth checking out a new copy over and over or deal with reverting *I have my reasons*) so I exported a copy and modified that. After modifying it I wanted to make a patch file of the changes. Since I exported it however there was no connection to the repo, or specifically the repo client I was using, so the client's diff/patch tools were useless. However, that is good, I would rather do it this way anyway. :)

Using the diff tool (utility, whatever) I got exactly what I wanted: a unified diff file of all the files in a directory (recursively) including newly added files, but not removed files and some other pesky files.

Here is the command I used:

diff -u -r -x '*.meta' --unidirectional-new-file ./repo_dir/ ./exported_dir/

Parameter Description
-u Unified diff
-r Recursively traverse the directory
-x '*.meta' Ignore all files ending in .meta (For Unity3D's "repo friendly-ness")
--unidirectional-new-file Include new files in the diff, but not removed ones (for that use -N)
./repo_dir/ Unmodified
./exported_dir/ Contains modified files


Diff's help and man pages are pretty sparse, the online manual is much better: http://www.gnu.org/software/diffutils/manual/

No comments:

Post a Comment