123456789101112131415161718192021 |
- #!/bin/bash
- # 从命令行参数获取分支名和正则表达式
- dev_branch=$(git branch --show-current)
- test_branch=$1
- grep_pattern=$2
- # 使用git diff命令查找test分支相对于dev分支修改的文件名,然后使用grep过滤文件名
- files=$(git diff --name-only ${dev_branch}..${test_branch} | egrep ${grep_pattern})
- # 使用for循环遍历文件名列表
- for file in $files; do
- # 判断文件是否存在
- if [ ! -f ${file} ]; then
- mkdir -p "$(dirname "${file}")"
- touch ${file}
- fi
- echo "git checkout ${test_branch} ${file}"
- git checkout ${test_branch} ${file}
- done
- git status
|