How to determine the unique number of changed lines in Git

Executing the following gives me the differences in line count between local changes and the remote versions of the file:

git diff --shortstat C:devSprint7 origin/master:C:devSprint7

Example result:

18 files changed, 11 insertions(+), 8 deletions(-)

Please, how do I calculate the total number of unique changed lines?

For instance, if line 5 of Login.jsp file is deleted and same line 5 is replace by another line (or string) (ie deletion and insertion is done on line 5), I want this to be counted as 1 changed line.

Can I get that count from the command above by summing the insertions and deletions?

Any help will be appreciated.


Here I am pasting a small shell script. Simply give the git diff command as input and rest will take care by the script itself.

#echo "Input Command : $1"
TOTAL_CHANGES_WITH_FILES="$($1 | grep '^+' | wc -l)"
TOTAL_CHANGED_FILES="$($1 | grep '^+++' | wc -l)"
RESULT=`expr ${TOTAL_CHANGES_WITH_FILES} - ${TOTAL_CHANGED_FILES}`
#echo "Total Changed Lines: ${RESULT}"
echo "${RESULT}"

save this code to file changed_lines.sh and run this file using command sh changed_lines.sh "git diff HEAD" . Replace "git diff HEAD" with the git diff C:devSprint7 origin/master:C:devSprint7 as per your config. This will simply print the no. of lines that changed. If anything wrong. please feel free to comment. Hope this helps.

链接地址: http://www.djcxy.com/p/47252.html

上一篇: 在Django项目中对代码行进行计数

下一篇: 如何确定Git中更改行的唯一编号