git_cp_file.sh 742 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. # 从命令行参数获取分支名和正则表达式
  3. dev_branch=$1
  4. test_branch=$2
  5. grep_pattern=$3
  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. # 判断文件是否存在于dev分支
  11. if git show ${dev_branch}:${file} &> /dev/null; then
  12. # 如果文件存在于dev分支,使用git checkout命令将文件从test分支复制到dev分支
  13. git checkout ${test_branch} ${file}
  14. else
  15. # 如果文件不存在于dev分支
  16. git show ${test_branch}:${file} > ${file}
  17. git add ${file}
  18. fi
  19. done
  20. git status