In practice, by using Git diff to calculate the number of code changes, there is a need to just count certain types of files (files with special suffix names/extensions), such as: Only the variables for files in the current git repo. java,. xml,. c,. cpp. There are two ways to make git count according to the file suffix name and to count the eligible files in each subdirectory.
1. Use the ' *.java ' and ' *.xml ' directly, if your git version is newer (for example: Git >= 1.7.8 version)
The code is as follows |
Copy Code |
jay@jay-linux:~/aew-backend.git$ git--version git version 1.7.9.5 jay@jay-linux:~/aew-backend.git$ ls Bug config.py lib MySQL readme.md repo shell jay@jay-linux:~/aew-backend.git$ git diff--shortstat e5ffef25 26c8d317-' *.py ' *.xml ' 4 files changed, insertions (+), deletions (-) |
2. The Globstar option, started with Bash 4.0, matches all files in the directory and all of its subdirectories with the end of. Py in this way, with no special requirements for GIT versions, whether your git is old or new. For Globstar, refer to the article "using the Globstart option in Bash", which I wrote earlier.
code is as follows |
copy code |
[repo@hosta aew-backend.git]$ git--version git version 1.7.1 [Repo@hosta aew-backend.git]$ shopt-s Globstar [Repo@hosta aew-backend.git]$ git diff--shortstat e5ffef25 26c8d317-**/*.py **/*.xml 4 files changed, insertions (+), Deletions (-) |