如何使 git diff --ignore-space-change 成为默认值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7310033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:46:59  来源:igfitidea点击:

How to make git diff --ignore-space-change the default

gitconfiggit-config

提问by boatcoder

I could probably setup an alias, but it seems like I should be able to set this as an option in the config file, only I don't see anyway to do it.

我可能可以设置一个别名,但似乎我应该能够将其设置为配置文件中的一个选项,只是我无论如何都看不到这样做。

I only want the --ignore-space-changewhen I'm doing diff, not when I'm doing apply or anything else. I'm trying to make the diff easier to understand by not cluttering it with with extraneous +/- lines that have no real changes on them.

我只想要--ignore-space-change我做 diff 的时候,而不是我做申请或其他任何事情的时候。我试图通过不使用无关紧要的 +/- 行来使差异更容易理解,而这些行没有真正的变化。

采纳答案by Dogbert

According to the Git Config manual, there's no such option. Your only option is to make an alias.

根据 Git Config 手册,没有这样的选项。您唯一的选择是创建别名。

http://git-scm.com/docs/git-config

http://git-scm.com/docs/git-config

回答by yjqg6666

You could use git aliasor bash aliasif you are using shell-available OS.

如果您使用 shell-available 操作系统,则可以使用git aliasbash alias

  1. git alias: Run this command to add alias:

    git config --global alias.dfw 'diff --ignore-space-change'

    --ignore-space-change can be abbreviated to -w
    to apply the alias using: git dfw

  2. bash alias: Run this command to add bash alias:

    echo "alias gitdfw='git diff --ignore-space-change'">>~/.profile

    Open a new terminal and you can directly run gitdfwto achieve the same.

  1. git alias:运行此命令以添加别名:

    git config --global alias.dfw 'diff --ignore-space-change'

    --ignore-space-change can be abbreviated to -w
    使用以下方法应用别名: git dfw

  2. bash alias:运行此命令以添加 bash 别名:

    echo "alias gitdfw='git diff --ignore-space-change'">>~/.profile

    打开一个新的终端,你可以直接运行gitdfw来达到同样的效果。

回答by Mark Longair

I'd agree with Dogbert's answerthat it's probably best to just use an alias, but another option is to set the config option diff.externalto a wrapper script that calls diffwith -b.

我同意Dogbert的答案,这可能是最好只使用一个别名,但另一种选择是将设置配置选项diff.external,以一个包装脚本,调用diff-b

回答by some helpful git

EDIT: I AM A FOOL AND DIDN'T READ YOUR REQUEST THROUGHLY

编辑:我是个傻瓜,没有通读你的请求

A way to achieve something similar, from man git-config:

一种实现类似目标的方法,来自man git-config

 apply.whitespace
       Tells git apply how to handle whitespaces, in the same way
       as the --whitespace option. See git-apply(1).

So open up your ~/.gitconfigor ./.git/config/and append

所以打开你的~/.gitconfigor./.git/config/并追加

[apply]
   whitespace = nowarn

It might also not let you commit something that only changes whitespace, but I'm sure you can overrule that with some flags.

它也可能不允许您提交仅更改空格的内容,但我相信您可以使用一些标志来否决它。

回答by Jo?o Pimentel Ferreira

Old question (2011), but now there's a shortcut git diff -wwhich stands for --ignore-all-space

老问题(2011),但现在有一个快捷方式git diff -w代表 --ignore-all-space

Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.

比较行时忽略空格。即使一行有空格而另一行没有空格,这也会忽略差异。

回答by Joseph Cheek

it would be great if this were possible with an option. but an alias works fairly well. here are the relevant lines from my .gitconfig:

如果有一个选项可以实现,那就太好了。但别名工作得相当好。这是我的 .gitconfig 中的相关行:

[diff]
    tool = mydiff
[difftool "mydiff"]
    cmd = "colordiff -NuBbwi \"$LOCAL\" \"$REMOTE\" | less -R"
[difftool]
    prompt = false
[alias]
    dt = difftool

this assumes using colordiff, which i recommend, giving you an almostexact copy of what git diffwould show, with two differences:

这假设使用我推荐的 colordiff,为您提供git diff将显示的内容的几乎精确副本,有两个不同之处:

  1. the --- line in colordiff is colored differently than the same line in git diff (very minor issue)
  2. each file is shown one at a time (annoying issue -- anyone know a fix?)
  1. colordiff 中的 --- 行的颜色与 git diff 中的同一行不同(非常小的问题)
  2. 每个文件一次显示一个(烦人的问题——有人知道解决办法吗?)

here's my /etc/colordiffrc:

这是我的 /etc/colordiffrc:

plain=off
newtext=green
oldtext=red
diffstuff=cyan
cvsstuff=red

Mac OS X 10.9.2, git version 1.8.5.2 (Apple Git-48)

Mac OS X 10.9.2,git 版本 1.8.5.2 (Apple Git-48)

(colordiff was obtained from brew)

(colordiff 是从 brew 获得的)