我有我的文本编辑器在保存文件时自动修剪尾部空白,并且我正在为一个开放源代码项目做出贡献,这个项目在尾部空白处存在严重问题。
每次我尝试提交补丁时,我都必须首先忽略所有只有空白的更改,才能仅选择相关信息。不仅如此,当我运行 git rebase 时,我通常会遇到几个问题,因为它们。
我希望能够以类似于 git add -p 的方式添加仅索引非空白更改,但无需自行选择所有更改。
有人知道如何做到这一点吗?
编辑:我无法更改该项目的工作方式,他们已经决定,在邮件列表上讨论它后,忽略这一点。 解决方案
@Frew解决方案不是我所需要的,所以这是我为完全相同的问题所做的别名: $ b $ pre $ alias.addnw = !sh -c'git diff -U0 -w --no-color$ @| git apply --cached --ignore-whitespace --unidiff-zero - '
运行:
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -更新
分别为 -U0 和 - unidiff-zero 添加了选项根据此评论,解决方法上下文匹配问题。
基本上它将应用在没有空白改变的情况下应用< add 的补丁。你会注意到,在 git addnw your / file 之后,仍然有未分离的更改,这是剩下的空白。
- 无颜色不是必需的,但因为我的颜色设置为始终,我必须使用它。无论如何,比对不起更安全。
I have my text editor to automatically trim trailing whitespace upon saving a file, and I am contributing to an open source project that has severe problems with trailing whitespace.
Every time I try to submit a patch I must first ignore all whitespace-only changes by hand, to choose only the relevant information. Not only that, but when I run git rebase I usually run into several problems because of them.
As such I would like to be able to add to index only non-whitespace changes, in a way similar that git add -p does, but without having to pick all the changes myself.
Does anyone know how to do this?
EDIT: I cannot change the way the project works, and they have decided, after discussing it on the mailing list, to ignore this.
解决方案@Frew solution wasn't quite what I needed, so this is the alias I made for the exact same problem:
alias.addnw=!sh -c 'git diff -U0 -w --no-color "$@" | git apply --cached --ignore-whitespace --unidiff-zero -'Or you can simply run:
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -Update
Added options -U0, and --unidiff-zero respectively to workaround context matching issues, according to this comment.
Basically it applies the patch which would be applied with add without whitespace changes. You will notice that after a git addnw your/file there will still be unstaged changes, it's the whitespaces left.
The --no-color isn't required but as I have colors set to always, I have to use it. Anyway, better safe than sorry.
更多推荐
仅添加非空白更改
发布评论