Merging code modifications

A few useful reminders for when I need to merge to directories of code whenever JHC or I come back from a trip and have code modifications to merge into our local code directory. This *usually* isn't simply a case of copying files over since modifications may have been done to the same file by different occasionally I have to merge individual changes (use the 'kompare' program for this...pretty handy).
1.  Clean both old and new directories of object files, core files and backup files using the following commands.  Do the removal of backup files last since the indent command will create lots of little ~ files for you!

	a. 	find . -name '*.o' -exec rm {} \;
	b.	find . -name 'core*' -exec rm {} \;
	c.	find . -name '*.c' -exec indent {} \;
	d. 	find . -name '*~' -exec rm {} \;

2.  Produce an ascii file that details the differences between the two directories (-b and -B convince diff to ignore changes in amounts of whitespace):
    The awk portion searches for 'diff -r, Binary file, and Only in' and insert a few newlines before each occurence (makes it more readable).

	a.	diff -rbB code_old/ code_new/ | awk '{if ($1 == "diff" || $1 == "Only" || $1 == "Binary") {printf("\n\n\n%s\n",$_); } else { print $_ }  }' > diff.out

3. Make a summary of the diff's using the following command:

	a.	diff -rbB --brief code_old/ code_new/ > diff.summary

	This allows you to get an overall view of the mods that were done.

4.  Peruse the summary file.  Note that step 1 above is not entirely necessary, but it sure makes this step much easier!!!!!!!!!  Vim is a nice editor for this since it colour codes much of the output of diff.

5.  Make a new directory for the merged code...decide which of the directories has the most mods done to it and use this as the new merged directory (since you'll have to move less files this way).

	a.      fgrep 'Only in code_old' diff.summary | wc -l
	b.      fgrep 'Only in code_new' diff.summary | wc -l

After deciding which of the directories has the most new files, make that the merged code directory:

	c.	cp -r code_???/ code_merged/

In case someone walks off with an old version of code and you want to pull out changes they've made, the following find command will list changes that have been made in the last 50 days, but only of files with a .c or .h extension:
	find code_jhc/ -mtime -50 -type f -regex '.*\(c\|h\)'

Last modified: July 12th, 2006, J. Beaudoin