git-quick-stats icon indicating copy to clipboard operation
git-quick-stats copied to clipboard

Count lines added deleted from Merge Commit

Open chiliang7 opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe.

Perhaps, the functionality exists but I couldn't find it but it would be nice to include lines added/deleted from the merge commits

Describe the solution you'd like The final output should include the line stats from merge commit

Thanks

chiliang7 avatar Jul 19 '23 01:07 chiliang7

I use a one-liner to extract info from a git command. For example, with git show, you get more data than needed. To filter it, use --shortstat and --format=, resulting in this:

 6 files changed, 366 insertions(+), 2 deletions(-)

You can use awk to extract numbers from text by specifying -F '[^0-9]+' as the field separator, which separates digits from non-digits in the input line. This allows you to isolate the numeric values.

awk -F '[^0-9]+' '{print $2","$3","$4}'

So, awk extracts the second (we skip the first field as it's a space), third, and fourth fields from the input. These fields contain the numbers we need, and awk prints them with commas in between:commas between:

6,366,2

Here's the complete command:

git show --shortstat --format= | awk -F '[^0-9]+' '{print $2","$3","$4}'

nnzv avatar Oct 12 '23 04:10 nnzv