1234567891011121314151617181920212223 |
- #!/bin/bash
- # 从命令行参数获取分支名和正则表达式
- dev_branch=$1
- test_branch=$2
- grep_pattern=$3
- # 使用git diff命令查找test分支相对于dev分支修改的文件名,然后使用grep过滤文件名
- files=$(git diff --name-only ${dev_branch}..${test_branch} | egrep ${grep_pattern})
- # 使用for循环遍历文件名列表
- for file in $files; do
- # 判断文件是否存在于dev分支
- if git show ${dev_branch}:${file} &> /dev/null; then
- # 如果文件存在于dev分支,使用git checkout命令将文件从test分支复制到dev分支
- git checkout ${test_branch} ${file}
- else
- # 如果文件不存在于dev分支
- git show ${test_branch}:${file} > ${file}
- git add ${file}
- fi
- done
- git status
|