简体   繁体   中英

Using name-only with other parameters in Git

I recently made some changes to a branch that consisted of 90% whitespace changes. Now I'd like to count how many files there were that received the other 10% of the changes. Is there a way to git diff while also passing other parameters such as --ignore-blank-lines ? git diff --name-only --ignore-blank-lines returns the entire list of all changed files, not the filtered list. If I omit --name-only then the diff shows the exact changes I want but all I want is the list of files, I don't care about the changes themselves.

Thanks!

Unfortunately, both --name-only and --name-status use shortcuts: they compare the stored trees (name and hash ID) without looking at the file contents . 1

What you'll need to do is use git diff (or git show ) with your whitespace options, then strip out all but the file names. For instance:

$ git show | grep '^diff '
diff --git a/file1 b/file1
diff --git a/file2 b/file2
$ git show --ignore-blank-lines | grep '^diff '
diff --git a/file2 b/file2

A bit more massaging (and/or the use of --no-prefix ) will get you just the file names without the a/ and b/ prefixes:

$ git show --ignore-blank-lines --no-prefix | grep '^diff '
diff --git file2 file2

1 If rename detection is enabled, the detector does examine the content of each file. However, it does not use the whitespace options, so this does not affect the results at all. The rest of the --name-status algorithm continues to just use the stored hash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM