1

I have an existing source-tree, with a bunch of sub-directories and thousands of source files. I have a new source-tree where some of the files have been updated and some new files/directories added.

The existing source-tree has a bunch of hidden sub-directories (.git) which the new source-tree lacks.

I'm looking for a way for all the updated and new files to find their way from the new source-tree to the existing. I don't mind for the similar files to be copied as well because it would have no adverse effect.

Flyk
  • 1,539
  • 1
  • 21
  • 28

1 Answers1

1

The first thing that comes to mind is rsync:

rsync -va /path/to/new/tree/ /path/to/existing/tree

The trailing slash on the first path is vital. Without it, a new tree folder will be created under /path/to/existing/tree, creating the path /path/to/existing/tree/tree.

This command will update the files in the existing tree with the files from the new tree.

John T
  • 163,373
  • 27
  • 341
  • 348
  • this works but not entirely as I expected. I've tried rsync -va new/ /old which almost works but it doesn't copy the .git directories under old to new perhaps a better way to describe what I'm trying to achieve is a merge where one side is given priority for when the same file is different in both locations. I want files that are only in old or only in new to be in the resulting merge. –  Jan 07 '10 at 11:35
  • ended up using the kdiff3 (http://kdiff3.sourceforge.net/) tool to merge things up –  Jan 07 '10 at 12:10
  • You can also use rsync's --include-from switch to read a file of folders to include. This way, you can sync all of the .git folders from old to new. To find all .git folders under old and put them in a file you can use `find /full/path/to/old -type d -name ".git" > gitfolders.txt`. Now we can use that file to sync only the .git folders back to new: `rsync -va --include-from 'gitfolders.txt' old/ new`. – John T Jan 07 '10 at 12:12