问题描述:

I have 2 directories which have the similiar structure.

./projectA

/directory1

/file1

/directory2

/file2

/file3

/file4

/directory3

/directoryA

./projectB

/directory1

/directory2

/file3

/directory3

/directoryB

I would like to merge projectA into projectB. If a directory or file existing in A and not existing in B, do svn copy from A to B to the according target. If a file in A has an according file in B, echo a warning. How can I do this automatically? It can be shell scripts or tools....

Thanks

网友答案:

With this command you get all files that are in projectA but not in projectB, ignoring the .svn folder:

diff -qr projectA projectB --exclude=.svn | grep "^Only in projectA:" | cut -d: -f2 | sed 's/^ *//g

With this command you get all files that exist in both folders and that differ (i.e. files you might need to check before copying):

diff -qr projectA projectB --exclude=.svn | grep "^Files " | cut -d" " -f2 | sed 's!projectA!!g'

The second command will not work with files that have spaces in them, though.

Now that you've got two lists with the file names you need, you can easily write a small script that does the right thing with them.

相关阅读:
Top