Is there a way to in a bash terminal mass recursive copy (cp -rf
equivalent) from one subdirectory to another, preserving the directory structure but ONLY copying files/directories are version controlled by git
?
The naive strategy would be...
cp -rf <targetDir> variantDir/; git add variantDir;
... but that would pick up a bunch of files that are data files dropped by the IDE, etc. I'm working with -- files which aren't currently version controlled in <targetDir>
.
As background, I have the following directory structure:
${baseDir}/
${baseDir}/variantA
Basically, ${baseDir}/
contains all the original version controlled content, and ${baseDir}/variantA
contains the content that differs for a targeted variant. For the original target folder ${baseDir}/variantA
is ignored. For the second target the folder variantA
is included, effectively superceding any content that matches other than the variantA
part of the path.
i.e. if I had:
${baseDir}/someFolder/someStuff.cpp
${baseDir}/variantA/someFolder/someStuff.cpp
It would use the second path for the second target, and the first path for the first target.
Now I'm adding variantB
and it's a full variant (unlike variantA
that has some fall through to the base target's files). It's closer to variantA
so I want to copy over everything in the base folder first, THEN copy over everything in the variantA
subfolder to the variantB
subfolder ... that way I have a new copy of all content (including the fall throughs) to version commit, with a preference for variantA
file versions, when such overlap exists.
I would use the naive snippet above, but I have a more fundamental problem that my IDE has dropped *.xml
files and other junk that git
is somehow smart enough to flag as not uncommitted content (probably language specific), but which cp
would ignore. I believe git
would copy these files if EXPLICITLY asked to do, so, hence I want to exclude all the non-git
controlled content, while using the general strategy stated prior.