I have multiple branches of a project checked out, each under their own directory (pretty standard).
我检查了一个项目的多个分支,每个分支都在他们自己的目录下(非常标准)。
src/branch1/some/code/directories src/branch2/some/code/directories
I often find myself wanting to copy selected files from one branch to another. An example would be copying cvsignore files, or intellij module files. The pseudocommand for what I'm trying to do is "copy all files under branch1 matching PATTERN to branch2, preserving the relative path of the copied file".
我经常发现自己想要将选定的文件从一个分支复制到另一个分支。一个例子是复制cvsignore文件或intellij模块文件。我正在尝试做的伪命令是“将branch1匹配PATTERN下的所有文件复制到branch2,保留复制文件的相对路径”。
This question looks close to what I'm looking for, but I need an OS X/linux/unix solution.
这个问题看起来很接近我正在寻找的东西,但我需要一个OS X / linux / unix解决方案。
1 个解决方案
#1
1
Use "cp -r --parents" command like this, in branch1 directory
在branch1目录中使用这样的“cp -r --parents”命令
find . -name ".cvsignore" -exec cp -r --parents {} ../branch2/ \;
OR
When in the src/ directory, run this script. You can get the variables from command line parameters if you want.
在src /目录中时,运行此脚本。如果需要,可以从命令行参数中获取变量。
SOURCE="branch1/"
TARGET="branch2/"
PATTERN=".cvsignore"
find $SOURCE -name $PATTERN | while read f ;
do
FILEPATH=$(dirname $f | cut -d'/' -f2-)
FILENAME=$(basename $f)
DESTPATH=$TARGET/$FILEPATH;
if [ ! -d $DESTPATH ]
then mkdir -p $DESTPATH
fi
cp $f $DESTPATH
done
#1
1
Use "cp -r --parents" command like this, in branch1 directory
在branch1目录中使用这样的“cp -r --parents”命令
find . -name ".cvsignore" -exec cp -r --parents {} ../branch2/ \;
OR
When in the src/ directory, run this script. You can get the variables from command line parameters if you want.
在src /目录中时,运行此脚本。如果需要,可以从命令行参数中获取变量。
SOURCE="branch1/"
TARGET="branch2/"
PATTERN=".cvsignore"
find $SOURCE -name $PATTERN | while read f ;
do
FILEPATH=$(dirname $f | cut -d'/' -f2-)
FILENAME=$(basename $f)
DESTPATH=$TARGET/$FILEPATH;
if [ ! -d $DESTPATH ]
then mkdir -p $DESTPATH
fi
cp $f $DESTPATH
done