5

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

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(-)

我可以运行一个命令来显示百分比变化而不考虑数量吗?我查看了git diff-tree,但它似乎只显示变化剧烈的时候。

4

2 回答 2

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

  2. 过滤掉---

  3. 过滤删除和上下文行

  4. 计算每个字节

于 2016-01-13T03:57:23.313 回答
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

然后agit 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%!

于 2016-01-06T13:41:48.053 回答