git_cp_file.sh 777 B

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