git-diff 有一个很酷的功能,记录如下:
--check Warn if changes introduce trailing whitespace or an indent that uses a space before a tab. Exits with non-zero status if problems are found. Not compatible with --exit-code.
我通常在提交之前使用 --check 运行 git-diff 并修复所有警告以保持代码整洁。 是否有任何脚本或工具可以解析 git-diff --check 的输出并自动修复所有警告?
最佳答案
本身并没有真正的脚本,但您可以很容易地使用 git apply --whitespace=fix 来清理补丁。从我的脑海中浮现出如下内容:
git commit -m 'this has diff --check errors'
git format-patch --stdout HEAD | git apply --index --whitespace=fix -
git commit --amend -C HEAD
如果您希望自动执行此操作,您可以尝试将其转换为提交后 Hook ,但要多加小心。
关于git - 是否有一个脚本可以修复 git-diff --check 警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12689237/