当前位置:   article > 正文

Linux 根据提交记录生成补丁及新旧文件对比

Linux 根据提交记录生成补丁及新旧文件对比
  1. #!/bin/bash
  2. #解决/bin/bash^M: bad interpreter: Text file busy
  3. #sed -i 's/\r$//' test1.sh
  4. CMD1=$1
  5. CMD2=$2
  6. CMD3=$3
  7. echo "CMD1 > $CMD1"
  8. echo "CMD2 > $CMD2"
  9. echo "CMD3 > $CMD3"
  10. # 运行时的入参 CMD1提交记录1 CMD2提交记录2 CMD3输出目录 ../diff/$CMD3
  11. if [ "$CMD1" == "" ];then
  12. echo "<<<<<<<<<<<<<<<<<<<<<< error"
  13. exit 0
  14. fi
  15. if [ "$CMD2" == "" ];then
  16. echo "<<<<<<<<<<<<<<<<<<<<<< error"
  17. exit 0
  18. fi
  19. if [ "$CMD3" == "" ];then
  20. CMD3="supplier"
  21. fi
  22. mkdir -p ../diff/$CMD3/old
  23. mkdir -p ../diff/$CMD3/new
  24. echo "mkdir"
  25. git log $CMD1 -1 --name-only |grep '/'| awk '{print $1}' > ../diff/list.txt
  26. # 查看$CMD1提交记录的文件列表
  27. xargs -a ../diff/list.txt cp --parents -t ../diff/$CMD3/old
  28. xargs -a ../diff/list.txt cp --parents -t ../diff/$CMD3/new
  29. echo "cp files"
  30. git diff $CMD2 $CMD1 > ../diff/$CMD3/list.diff
  31. echo "new list.diff"
  32. # 根据$CMD1提交记录对比前一条提交记录$CMD2生成差异文件
  33. cd ../diff/$CMD3/old
  34. patch -R -p1 <../list.diff
  35. echo "patch list.diff"
  36. # 打补丁
  37. echo "<<<<<<<<<<<<<<<<<<<<<< finish"
  38. exit 0

根据两个提交记录CMD1和CMD2生成差异文件list.diff,并根据CMD1的修改文件列表复制修改前的文件到old目录,修改后的文件到new目录

参考链接:

git导出差异文件及目录结构 - 我是橘子 - 博客园 (cnblogs.com)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/518336
推荐阅读
相关标签
  

闽ICP备14008679号