打印不相似的百分比

时间:2016-01-06 05:05:00

标签: git git-commit git-diff git-diff-tree

有时,当您彻底更改文件时,会触发重写:

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

结果:

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

然而,对于较小的更改,这不会发生:

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

结果:

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

我可以运行一个命令,无论金额多少都会显示百分比变化吗? 我调查了Jenkins set up 1,但它似乎只显示了什么时候 变化很大。

2 个答案:

答案 0 :(得分:3)

git diff -U10000 | awk '
/^i/ {getline; next}
/^-/ {pa += length}
/^ / {qu += length}
END {printf "%.0f%\n", pa/(pa+qu)*100}
'
  1. 使用-U10000

  2. 强制完整上下文
  3. 过滤掉---

  4. 过滤删除和上下文行

  5. 为每个

  6. 计算字节数

答案 1 :(得分:0)

使用最新的git:

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

我用:

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

然后git diff -B1%/1%给了我:

> 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%!