我们想要运行git filter-branch一个大型代码库来重新格式化 PHP 文件。由于我们有超过 21k 次提交,phpcbf因此希望每次提交filter-branch. 是否可以只获取每次提交更改的文件并对其进行专门格式化?就像是...
git filter-branch --tree-filter \
'FILES=$(<something> | grep .php) php /usr/local/bin/phpcbf.phar $FILES || true'
Run Code Online (Sandbox Code Playgroud)
我找到了解决方案:
\n\ngit filter-branch --tree-filter \'phpcbf $(\\\n git show $GIT_COMMIT --name-status | egrep ^[AM] |\\\n grep .php | cut -f2)\' -- --all\nRun Code Online (Sandbox Code Playgroud)\n\n只是为了快速概述一下它\xe2\x80\x99s 正在做什么:
\n\ngit show $GIT_COMMIT --name-status将返回该提交的所有修改文件。egrep ^[AM]将雕像过滤为仅添加和修改。无需尝试格式化正在删除的文件。grep .php仅格式化 PHP 文件。cut -f2从列表中删除状态前缀,以便我们只获取原始文件路径。有关更多详细信息,请参阅我的博客文章: https: //elliot.land/post/reformatting-your-codebase-with-git-filter-branch
\n| 归档时间: |
|
| 查看次数: |
1347 次 |
| 最近记录: |