git_cp_file.sh 613 B

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