bash - 遍历 git diff --name-only 文件和操作
问题描述
我在 GitHub Actions 中运行的 shell 脚本代码会获得更改,最终我想要发生的是在输出中为每个文件获取文件类型和文件名的回显。
echo "Git Add --all"
git add --all
echo "Add to Files:"
files= git diff --name-only --cached
echo "*************************************************************"
echo "GIT diff:"
echo ""
git diff --name-only --cached
echo ""
echo "*************************************************************"
echo "Files:"
echo $files
for file in $files; do
if [ "$file" == "*.cls" ] # this is the snag
then
echo "$file Class Updated"
fi
if [ "$file" == "*.flow" ] # this is the snag
then
echo "$file Flow Updated"
else
echo "$file not found"
fi
done
运行时我得到一个输出
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: src/classes/xxxx.cls
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/flows/
no changes added to commit (use "git add" and/or "git commit -a")
Git Add --all
Add to Files:
src/classes/xxx.cls
src/flows/xxxx.flow
*************************************************************
GIT diff:
src/classes/xxx.cls
src/flows/xxxx.flow
*************************************************************
Files:
files 变量没有被分配来自 git diff 的输出,一旦发生这种情况,for 循环是否会起作用?
在这方面,我是一个极端的新手,我非常需要任何帮助。非常感谢社区中的所有人
解决方案
推荐阅读
- javascript - 如何预加载角度路线并仅在路线成功加载后切换?
- php - laravel 可终止的中间件 - 在将响应发送到浏览器后是否对其进行处理?
- java - Convert Kotlin Unit to Java Void
- java - 循环播放媒体项目
- javascript - 当我缩小页面时,“rcorners2”类的框在某些部分离开页面。我该如何解决这个问题,使其顺利缩小?
- python - Python - groupby sum map to another dataframe
- python - In Python, how to delete some words in a string according to a list?
- node.js - gulp-watch 只运行一次
- arrays - 如何连接三个二维数组,它们各自的数组中包含色调、饱和度和强度值,并将其显示为图像?
- c++ - 如何刷新 Windows 中的所有文件缓冲区?