有没有添加git显示行,更改行和删除行的方法? [英] Is there a way of having git show lines added, lines changed and lines removed?
问题描述
$ b $
$ git diff - C --stat HEAD c9af3e6136e8aec1f79368c2a6164e56bf7a7e07
app / controllers / application_controller.rb | 34 +++ -------------------------
1个文件已更改,4个插入(+),30个删除( - )
但是实际发生的事情是,4行被更改,26行被删除,这与添加4行并删除30个。
有没有办法获得delta delta(本例中是26)?我并不在乎区分添加或删除的行。
您可以使用:
git diff --numstat
获得数字差异信息。
至于从添加和删除对分离修改, - word-diff
可能会有所帮助。您可以尝试如下所示:
MOD_PATTERN ='^。+(\ [ - | \ {\ +)) 。* $'
ADD_PATTERN ='^ \ {\ +。* \ + \} $'
REM_PATTERN ='^ \ [ - 。* - \] $'
git diff --word-diff --unified = 0 | sed -nr \
-es / $ MOD_PATTERN / modified / p\
-es / $ ADD_PATTERN / added / p\
-es / $ REM_PATTERN / removed / p\
|排序| uniq -c
这有点冗长,所以您可能需要在自己的脚本中解析它。
"git diff --stat" and "git log --stat" shows things like:
$ git diff -C --stat HEAD c9af3e6136e8aec1f79368c2a6164e56bf7a7e07
app/controllers/application_controller.rb | 34 +++-------------------------
1 files changed, 4 insertions(+), 30 deletions(-)
But what really happened in that commit was that 4 lines were changed and 26 lines were deleted which is different than adding 4 lines and deleting 30.
Is there any way of getting the delta LOCs (26 in this case)? I don't really care about differentiating between lines added or removed.
You can use:
git diff --numstat
to get numerical diff information.
As far as separating modification from an add and remove pair, --word-diff
might help. You could try something like this:
MOD_PATTERN='^.+(\[-|\{\+).*$'
ADD_PATTERN='^\{\+.*\+\}$'
REM_PATTERN='^\[-.*-\]$'
git diff --word-diff --unified=0 | sed -nr \
-e "s/$MOD_PATTERN/modified/p" \
-e "s/$ADD_PATTERN/added/p" \
-e "s/$REM_PATTERN/removed/p" \
| sort | uniq -c
It's a little long-winded so you may want to parse it in your own script instead.
这篇关于有没有添加git显示行,更改行和删除行的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!