量化git diff中的变化量? [英] Quantifying the amount of change in a git diff?

查看:147
本文介绍了量化git diff中的变化量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git来实现一个不太寻常的目的 - 当我写小说时,它存储我的文本。 (我知道,我知道... geeky。)

我试图跟踪生产力,并且想要测量后续提交之间的差异程度。作家的工作代理人是写出的文字,至少在创作阶段。我不能使用直接的字数,因为它忽略了编辑和压缩,这两个都是写作的重要部分。我想跟踪:

pre $ (加入单词)+(单词删除)



这将会重复计算(单词已更改),但我没有问题。



输入一些魔法咒语并且让git报告这个距离度量值用于任何两个修订版本会很棒。然而,git diffs是补丁,即使你只在一行上混合了一个字符,也可以显示整行代码;我不想那样,特别是因为我的'线'是段落。理想情况下,我甚至可以指定word的含义(尽管\W +可能是可以接受的)。



是否有git-diff在逐字的基础上给出差异?或者,有没有一种解决方案使用标准的命令行工具来计算以上的度量??解决方案

wdiff 不会逐字比较。可以将Git配置为使用外部程序进行差异化。根据这两个事实和这篇博文 ,下面应该做大致你想要的。



创建一个脚本来忽略大多数不必要的参数,它们是 git-diff 提供并将它们传递给 wdiff 。将以下内容保存为〜/ wdiff.py 或其他类似内容,并将其设置为可执行文件。

 #!/ usr / bin / python 

import sys
import os

os.system('wdiff -s3%s% s'%(sys.argv [2],sys.argv [5]))

告诉 git 来使用它。

  git config --global diff.external 〜/ wdiff.py 
git diff文件名


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 measure the degree of difference between subsequent commits. The writer's proxy for "work" is "words written", at least during the creation stage. I can't use straight word count as it ignores editing and compression, both vital parts of writing. I think I want to track:

 (words added)+(words removed)

which will double-count (words changed), but I'm okay with that.

It'd be great to type some magic incantation and have git report this distance metric for any two revisions. However, git diffs are patches, which show entire lines even if you've only twiddled one character on the line; I don't want that, especially since my 'lines' are paragraphs. Ideally I'd even be able to specify what I mean by "word" (though \W+ would probably be acceptable).

Is there a flag to git-diff to give diffs on a word-by-word basis? Alternately, is there a solution using standard command-line tools to compute the metric above?

解决方案

wdiff does word-by-word comparison. Git can be configured to use an external program to do the diffing. Based on those two facts and this blog post, the following should do roughly what you want.

Create a script to ignore most of the unnecessary arguments that git-diff provides and pass them to wdiff. Save the following as ~/wdiff.py or something similar and make it executable.

#!/usr/bin/python

import sys
import os

os.system('wdiff -s3 "%s" "%s"' % (sys.argv[2], sys.argv[5]))

Tell git to use it.

git config --global diff.external ~/wdiff.py
git diff filename

这篇关于量化git diff中的变化量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆