Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an existing source-tree, with a bunch of subdirectories 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 subdirectories (.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.

share|improve this question
    
I'm assuming you're on Linux? –  John T Jan 7 '10 at 10:19
    
yes (on mac osx) –  user23935 Jan 7 '10 at 10:23
add comment

1 Answer

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.

share|improve this answer
    
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. –  user23935 Jan 7 '10 at 11:35
    
ended up using the kdiff3 (kdiff3.sourceforge.net) tool to merge things up –  user23935 Jan 7 '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 7 '10 at 12:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.