Git-diff view diff variance information based on file name extension

Source: Internet
Author: User
Tags diff using git

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 (-)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.