Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在gitlab中只显示和修改文件?_Php_Git_Gitlab - Fatal编程技术网

Php 如何在gitlab中只显示和修改文件?

Php 如何在gitlab中只显示和修改文件?,php,git,gitlab,Php,Git,Gitlab,我的gitlab-ci.yml中有以下命令,它在提交时更改的每个php文件上运行“php-l”: test: stage: test script: - for file in $(git diff --name-only HEAD HEAD~1 | egrep "\.php$"); do php -l $file; done 我遇到的问题是,如果删除了一个php文件,它也会尝试删除该文件,但由于该文件不存在而失败 如何让它只检查存在的已更改的PHP文件?您可以使用git di

我的gitlab-ci.yml中有以下命令,它在提交时更改的每个php文件上运行“php-l”:

test:
  stage: test
  script:
    - for file in $(git diff --name-only HEAD HEAD~1 | egrep "\.php$"); do php -l $file; done
我遇到的问题是,如果删除了一个php文件,它也会尝试删除该文件,但由于该文件不存在而失败


如何让它只检查存在的已更改的PHP文件?

您可以使用
git diff--name status
选项。此命令的返回方式如下:

A       a.php # added file
D       b.php # deleted file
M       c.php # modified file
请查看更多详细信息。

以下命令使用此选项并检查除已删除文件外的语法:

test:
  stage: test
  script:
    - for file in $(git diff --name-status HEAD~1 HEAD | egrep "^[ACMR].*\.php$" | cut -c 3-); do php -l $file; done

git diff--name status HEAD HEAD~1
返回反向文件状态,因此我执行了
git diff--name status HEAD~1 HEAD

这真的很好,但我对重命名的文件(即:更改了位置的文件)有一个问题。首先感谢@kuromoka提供了这个很棒的一行代码!:)@David对于重命名,我决定添加一个快速检查文件是否存在的方法,如下所示:
用于$(git diff——name status HEAD~1 HEAD|egrep)^[ACMR].\.php$“| cut-c3-);do[-f$file]&&php-l$file;完成