Print percent dissimilarity

Sometimes, when you radically change a file, it starts rewriting:

yes | head -256 > pa.txt
git add .
git commit -m qu
truncate -s128 pa.txt
yes n | head -64 >> pa.txt
git commit -am ro

Result:

[master 79b5658] ro
 1 file changed, 128 insertions(+), 256 deletions(-)
 rewrite pa.txt (75%)

However, this does not happen with smaller changes:

yes | head -128 > pa.txt
git add .
git commit -m qu
truncate -s64 pa.txt
yes n | head -32 >> pa.txt
git commit -am ro

Result:

[master 88ef937] ro
 1 file changed, 32 insertions(+), 96 deletions(-)

Is it possible to run a team that will show the percentage change regardless of the amount? I looked at git diff-tree , but again it seems that it only displays when the change is strong.

+4
source share
2 answers
git diff -U10000 | awk '
/^i/ {getline; next}
/^-/ {pa += length}
/^ / {qu += length}
END {printf "%.0f%\n", pa/(pa+qu)*100}
'
  • Set full context with -U10000

  • Filter ---lines

  • Filter in deletions and context lines

  • The number of bytes for each

+1
source

With the latest git:

> git --version
git version 2.7.0.windows.1

I use:

git init dissimilarity
cd dissimilarity
yes aaa | head -128 > pa.txt
git commit -am qu
<remove a few lines>
yes n | head -32 >> pa.txt
git commit -am ro

Then a git diff -B1%/1%gives me:

> git diff -B1%/1% @~|grep diss
dissimilarity index 14%

, pa.txt, , :

> git diff @~
diff --git a/pa.txt b/pa.txt
index 7f9bf77..bf32d0b 100644
--- a/pa.txt
+++ b/pa.txt
@@ -107,13 +107,7 @@ aaa
 aaa
 aaa
 aaa
-n
-n
-n
-n
-n
-n
-n
+sss
 n
 n
 n

:

> git diff -B1%/1% @~|grep diss
dissimilarity index 2%

2%!

0

Source: https://habr.com/ru/post/1623021/


All Articles