I need to use the git-log
command to create a report of the number of added and removed lines by commit, on average between two dates.
Currently the command I use is:
git log --since="2015-12-01" --until="2015-12-31" --shortstat
But I need to filter some files in the process.
Thoses files are autogenerated, and we don't want to see their influence. They are easily recognizes by their name *.generated.*
I choose to use the git-log
command, I am able to get the report I need, except I don't see how to filter those unwanted files.
The doc is big, I already read it several times, but I don't see anything about filtering files based on their names. Is this possible, or do I have to find another command to find the number of lines added/deleted by commit?
Note that by using the “git rm” command, the file will also be deleted from the filesystem. Also, you will have to commit your changes, “git rm” does not remove the file from the Git index unless you commit it.
The pathspec is the mechanism that git uses for limiting the scope of a git command to a subset of the repository. If you have used much git, you have likely used a pathspec whether you know it or not. For example, in the command git add README.md , the pathspec is README.md .
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
With git log --follow , Git runs an after-diff step (called from diff_tree_sha1 ; see footnotes) that trims everything down to one file. The diff is done with R=C and L=P. The general case is actually easier to describe, though, so we'll start with that.
The "secret" on how to do it is called:
pathspec magic
You Can simply use this format (introduced 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.*"
This syntax is called pathspec magic
.
Using this syntax you can "tell" git which file extensions to exclude. In your case it's the *.generated.*
http://git-scm.com/docs/gitglossary.html
:
A pathspec that begins with a colon
:
has special meaning.In the short form, the leading colon
:
is followed by zero or moremagic signature
letters (which optionally is terminated by another colon :), and the remainder is the pattern to match against the path.The
magic signature
consists of ASCII symbols that are neither alphanumeric, glob, regex special characters nor colon. The optional colon that terminates themagic signature
can be omitted if the pattern begins with a character that does not belong to "magic signature" symbol set and is not a colon.In the long form, the leading colon
:
is followed by a open parenthesis (, a comma-separated list of zero or moremagic words
, and a close parentheses ), and the remainder is the pattern to match against the path.
Note
In older versions (the feature was introduced in git v1.9 and the bug was fixed in git 1.9.5) there was a bug which was fixed.
https://github.com/git/git/commit/ed22b4173bd8d6dbce6236480bd30a63dd54834e
git log --stat
(check the last commit)
And the same runt with the filer - you can see that there is only one file in the results instead of 2
git log --stat -p -- . ':(exclude)*dal.js*'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With