让git撤消任何只有空白的变化? [英] Make git undo any whitespace-only changes?

查看:117
本文介绍了让git撤消任何只有空白的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法可以自动对任何只有空白变化的文件进行git checkout?我正在处理Windows和一些从Eclipse运行的代码生成,所以我得到了新行更改和空白变化,这些变化正在堵塞我的工作流程,并且很难跟踪实际的变化。



对于报告,即使只是一种很好的方式,哪些文件具有真正的变化,哪些不会是一个开始,而不必为每个文件执行diff -w 如果您的更改没有被暂存

只是空白的变化,你可以这样做:



git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -



之后,要移除所有未分离的更改只能用空格),你可以这样做:

git checkout。



如果您的更改正在执行



通过执行 git reset --mixed 和从这个答案的顶部继续。请注意, mixed 是默认模式,可以省略。


Is there an easy way to automatically do a git checkout on any file that only has whitespace changes? I'm dealing with both Windows and some code generation that's run from Eclipse, so I get newline changes and whitespace changes that are clogging up my workflow with noise, and making it difficult to track actual changes.

Even just a nice way to report which files have real changes and which don't would be a start, rather than having to do a diff -w for each one

解决方案

If your changes are not staged

To stage changes that are not just whitespace changes, you can do:

git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -

Afterwards, to remove all unstaged changes (those changes that differ only in whitespace), you can do:

git checkout .

If your changes are staged

Unstage your changes by doing a git reset --mixed and continue from the top of this answer. Note that mixed is the default mode and can be omitted.

这篇关于让git撤消任何只有空白的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆