git diff --stat exclude certain files

强颜欢笑 提交于 2019-11-30 11:54:22

The exclude pathspec trick, described in Making 'git log' ignore changes for certain paths, works here:

git diff --stat -- . ':(exclude)file/to/exclude.txt'

or, if you are in a subdirectory:

git diff --stat -- :/ ':(exclude,top)file/to/exclude.txt'

The latter can be spelled in various ways. For instance, this also works:

git diff --stat ':(top)' :!/file/to/exclude.txt

as does:

git diff --stat :/: :!/:file/to/exclude.txt

These are described in the gitglossary documentation under the "pathspec" section. Note that the exclude feature is new in Git version 1.9 (and slightly broken until 1.9.2). The leading / is an alias for top and the ! is an alias for exclude, with the long forms requiring the parentheses. The trailing colon before the actual pathname is optional when using the single-character aliases but forbidden when using the parentheses (this rule trips me up every time—I keep wanting to use :(exclude):... rather than :(exclude)...). The single quotes around the (top) and (exclude) pathspec components above are to protect the parentheses from being interpreted by the (Unix/Linux) shells; the Windows shell may have different ideas about which characters need protection.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!