admin管理员组

文章数量:1191728

When I execute git show on an existing commit, the output is full of highlighted whitespace errors; especially trailing whitespace and carriage returns. It's very annoying, since this is someone else's old commit that was merged a long time ago, so it's not like I can do anything about it now.

I can suppress these with the right arguments to e.g. git config --global core.whitespace cr-at-eol. That works fine.

The thing is, I want those warnings with git diff. I want to know before I check in a file with broken whitespace. I just don't want to see the warnings on commits I can't change anyway.

Is there a way to set cr-at-eol, etc. just for git show?

When I execute git show on an existing commit, the output is full of highlighted whitespace errors; especially trailing whitespace and carriage returns. It's very annoying, since this is someone else's old commit that was merged a long time ago, so it's not like I can do anything about it now.

I can suppress these with the right arguments to e.g. git config --global core.whitespace cr-at-eol. That works fine.

The thing is, I want those warnings with git diff. I want to know before I check in a file with broken whitespace. I just don't want to see the warnings on commits I can't change anyway.

Is there a way to set cr-at-eol, etc. just for git show?

Share Improve this question asked Jan 24 at 1:45 Edward FalkEdward Falk 10.1k11 gold badges82 silver badges123 bronze badges 1
  • It’s kind of indirect but maybe --ignore-space-change would work for your case. – Guildenstern Commented Jan 24 at 8:16
Add a comment  | 

2 Answers 2

Reset to default 2

You can run this command to have the expected behaviour:

git -c core.whitespace=cr-at-eol show

git -c allows you to override configuration parameters for the current command (it's not saved in the config).

If you want to read more about git -c: https://git-scm.com/docs/git#Documentation/git.txt--cltnamegtltvaluegt

The config parameters are a persistent way to set a number of flags which can also be set with regular command line arguments.

For example:

git show --no-cr-at-eol ...

These options are listed in git help show

If you are looking for a shortcut to use these options repeatedly, you can set an alias:

# run once:
git config --global alias.view "show --no-cr-at-eol"

# you can now type:
git view ...

本文标签: Suppress whitespace warnings in git show but not git diffStack Overflow