Php cs fix only formats the modified code/only formats the submitted code Author: Chuwen Time: 2023-09-21 Classification: PHP ##Premises Note that you need to add 'cs fix': "php cs fix $1" 'in the' scripts: 'section of' composer. json ', as shown in the following example ```json { "name": "hyperf/hyperf-skeleton", "type": "project", // ... "autoload": { "psr-4": { "App\\": "app/" }, "files": [] }, "scripts": { // ...... "cs-fix": "php-cs-fixer fix $1", // ...... }, } ``` ##Command ###Only format the modified code ```shell git diff --name-only --cached | grep '\.php$' | xargs -n1 composer cs-fix ``` 1. 'git diff -- name only -- cached': This part of the command is used to obtain the list of modified files that you have staged. 2. 'grep' . Php $'': pipe the file list to the grep command, which will only select files with the extension '. php'. 3. 'xargs - n1 composer cs fix': The xargs command passes each file name as a parameter to the 'composer cs fix' command to format the code of each file. ###Format a submitted code ```shell git diff-tree --no-commit-id --name-only -r <commit-hash> | grep '\.php$' | xargs -n1 composer cs-fix ``` 1. 'git diff tree -- no commit id -- name only - r<commit hash>': This command obtains the modified file list in a specific submission record. >* *<commit hash>* * Can be obtained from ` git log ' 2. 'grep' . Php $'': pipe the file list to the 'grep' command, which will select only files with the extension '. php'. 3. The 'xargs - n1 composer cs fix': 'xargs' command passes each file name as a parameter to the' composer cs fix 'command to format the code of each file. label: PHP , Composer