我们希望在一个大型代码库上运行
git filter-branch
重新格式化PHP文件。由于我们有超过21k个提交,每次filter-branch
提交时phpcbf
都想要格式化整个代码库。是否可能只获取每个提交更改的文件并对它们进行特定的格式化?类似于…git filter-branch --tree-filter \
'FILES=$(<something> | grep .php) php /usr/local/bin/phpcbf.phar $FILES || true'
git diff
的某些行为已经改变(我正在运行git 2.10.2)。它一直在与我的最新HEAD进行比较,而不是过滤后提交的父级。我能够稍微修改Elliot的代码使其正常工作。在过滤期间,我使用了git show $GIT_COMMIT --name-status
而不是git diff --cached --name-status
。$GIT_COMMIT
在每个filter-branch
步骤中都会自动设置。 - Andy Fowlergit show $GIT_COMMIT --name-only --pretty=oneline|tail -n +2
比git show $GIT_COMMIT --name-status | egrep ^[AM]
更健壮。请注意,它还会返回已删除的文件,因此您可能需要测试文件是否存在。 - Gabriel Devillers