Quantifying the amount of change in a git diff?

前端 未结 9 2047
不思量自难忘°
不思量自难忘° 2020-12-13 17:38

I use git for a slightly unusual purpose--it stores my text as I write fiction. (I know, I know...geeky.)

I am trying to keep track of productivity, and want to meas

9条回答
  •  醉酒成梦
    2020-12-13 18:34

    I figured out a way to get concrete numbers by building on top of the other answers here. The result is an approximation, but it should be close enough to serve as a useful indicator of the amount characters that were added or removed. Here's an example with my current branch compared to origin/master:

    $ git diff --word-diff=porcelain origin/master | grep -e '^+[^+]' | wc -m
    38741
    $ git diff --word-diff=porcelain origin/master | grep -e '^-[^-]' | wc -m
    46664
    

    The difference between the removed characters (46664) and the added characters (38741) shows that my current branch has removed approximately 7923 characters. Those individual added/removed counts are inflated due to the diff's +/- and indentation characters, however, the difference should cancel out a significant portion of that inflation in most cases.

提交回复
热议问题