stat排除某些文件

stat排除某些文件

本文介绍了git diff --stat排除某些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图修改中排除文件> - stat 标志并失败 - (创建驱动程序)似乎只有unix (重定向到/ bin / true,无论这意味着什么)加上它会创建一个驱动程序并将其永久分配给文件类型,而我正在寻找一个开关来临时禁用文件(或者某些文件)的diff。



脚本:

  git diff`git status -s | grep -v ^ \ D | grep -v file / to / exclude.txt | cut -b4-`

实际上调用git状态并编辑它的输出 - 而我想要的是指示git diff本身忽略某些文件,同时计算(简单)--stat(只是行更改)。我浏览了文档,但似乎无法找到这样的选项。任何人都可以帮我吗?

  $ git --version 
git 2.6.1.windows.1


解决方案

排除pathspec技巧,在, git diff --status - 。 ':(exclude)file / to / exclude.txt'

或者,如果您位于子目录:

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

后者可以以各种方式拼写。例如,这也适用:

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

同样如此:

<$ p $

这些在下的pathspec部分。请注意,排除功能是Git版本1.9中的新增功能(并且在1.9.2之前略微打破)。领先的 / top 的别名。是 exclude的一个别名,长表单需要括号。实际路径名前的尾部冒号在使用单字符别名时是可选的,但在使用括号时禁止(这个规则每次都会让我绊倒 - 我一直希望使用 :(排除):...) 而不是 :(排除)... )。上面的(顶部)(排除) pathspec组件的单引号是为了保护圆括号不被解释(Unix / Linux)shell; Windows shell可能对哪些字符需要保护有不同的看法。


Trying to adapt the answers from Want to exclude file from "git diff" for the --stat flag and failing - the accepted answer (create a driver) seems unix only (redirect to /bin/true, whatever this means) plus it creates a driver and assigns it to the file kind of permanently, while I am looking for a switch to temporarily disable the diff for a file (or rather some files).

The scripting solution:

git diff `git status -s |grep -v ^\ D |grep -v file/to/exclude.txt |cut -b4-`

actually calls git status and edits its output - while what I want is to instruct git diff itself to ignore some files while calculating the (simple) --stat (just lines changed). I went through git-diff docs but can't seem to find such an option. Anyone give me a hand ?

$ git --version
git version 2.6.1.windows.1
解决方案

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

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

or, if you are in a subdirectory:

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

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

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

as does:

git diff --status :/: :!/: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.

这篇关于git diff --stat排除某些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 11:13