Git log - How to filter (exclude) files from `Git log`? (Git magic path)

I need to use the git-log command to create a report on the number of added and deleted rows by fixing on average between two dates.

I am currently using the command:

 git log --since="2015-12-01" --until="2015-12-31" --shortstat 

But I need to filter out some files in this process. Thoses files are automatically generated, and we do not want to see their impact. They are easily recognized by their name *.generated.*

I choose to use the git-log command, I can get the report that I need, but I don’t see how to filter these unwanted files.

The document is large , I already read it several times, but I see nothing about filtering files based on their names. Is this possible, or do I need to find another command to find the number of rows added / deleted with commit?

+5
source share
1 answer

The "secret" on how to do this is called:


pathspec magic


You can simply use this format (presented in git version> 1.9):

 # Use this syntax, pay attention to all the parameters and the syntax # Unix: git log <any required flags> -p -- . ':(exclude)*.generated.*' # Windows (double quote) [ Thank to @Cyril Gandon for noticing it]: # (double quote) should work on all OS as well git log <any required flags> -p -- . ":(exclude)*.generated.*" 

What is this weird syntax?

This syntax is called pathspec magic .
Using this syntax, you can tell git which file extensions to exclude. In your case, this is *.generated.*


From the doc:

http://git-scm.com/docs/gitglossary.html

A pathspec starting with a colon : has special meaning.

In short form, before the colon begins : should be zero or more magic signature letters (which optionally end with another colon :), and the remainder is a template that matches the path.

magic signature consists of ASCII characters that are not alphanumeric, global, regular expressions, or colons. The optional colon that completes the magic signature may be omitted if the pattern starts with a character that does not belong to the magic signature character set and is not a colon.

In long form, before the colon begins : an open parenthesis follows (a comma-separated list, zero or more magic words , and close parentheses), and the remainder is a pattern that will match the path.


Note

In older versions (the function was introduced in git v1.9, and the bug was fixed in git 1.9.5), the bug was fixed.

https://github.com/git/git/commit/ed22b4173bd8d6dbce6236480bd30a63dd54834e


Demo:

git log --stat

(mark the last commit)
enter image description here

And the same runt with a filter - you can see that there is only one file in the results instead of 2

git log --stat -p -- . ':(exclude)*dal.js*'

enter image description here

+8
source

Source: https://habr.com/ru/post/1244360/


All Articles