git_cp_file.sh 780 B

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