git - 是否有一个脚本可以修复 git-diff --check 警告?

标签 git removing-whitespace git-diff

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/

相关文章:

git - 我如何漂亮地打印出 git-diff 输出?

git diff 只有我的改变

git - 尝试设置 heroku 暂存站点 - "Resource not found "

java - JGit 显示远程更改,如 git diff --name-status master origin/master

java - jgit - 删除 .git 目录(或获取没有它的文件)

python - 如何删除字符串python中的特定空格

git - 如何让 git-status 检查两个不同的 Remote ?

c# 去除多余空格的最快方法

c - 删除字母之间的制表符和空格 - 段错误

Git 显示整个文件的变化