首页 > 解决方案 > 遍历 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 循环是否会起作用?

在这方面,我是一个极端的新手,我非常需要任何帮助。非常感谢社区中的所有人

标签: bashgitloopsshelldiff

解决方案


推荐阅读