我可以让git diff只显示更改的文件名和行号吗? [英] Can I make git diff only show the changed file names and line numbers?

查看:2237
本文介绍了我可以让git diff只显示更改的文件名和行号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我不想看到更改的内容,只是文件名和行号。

:如果您只是寻找已更改文件的名称(,而不是已更改行的行号),则这很容易,点击此链接到另一个答案






这里没有内置选项(我认为它也不是那么有用),但是它可以在git中执行此操作,在一个外部差异脚本。



这是一个非常糟糕的;这将取决于你如何修改你想要的输出。

 #! / bin / sh 

#运行以下命令:
#GIT_EXTERNAL_DIFF =< script of name> git diff ...

case $#
1)unmerged file $ @,无法显示行号; 1号出口;;
7);;
*)echo我不知道该怎么做,帮忙!; 1号出口;;
esac

path = $ 1
old_file = $ 2
old_hex = $ 3
old_mode = $ 4
new_file = $ 5
new_hex = $ 6
new_mode = $ 7

printf'%s:'$ path
diff $ old_file $ new_file | grep -v'^ [<>]'

有关外部差异的详细信息,请参阅在 git手册页面< GIT_EXTERNAL_DIFF / a>(在700行左右,非常接近结尾)。


Basically, I don't want to see the changed content, just the file names and line numbers.

解决方案

Note: if you're just looking for the names of changed files (without the line numbers for lines that were changed), that's easy, click this link to another answer here.


There's no built-in option for this (and I don't think it's all that useful either), but it is possible to do this in git, with the help of an "external diff" script.

Here's a pretty crappy one; it will be up to you to fix up the output the way you would like it.

#! /bin/sh
#
# run this with:
#    GIT_EXTERNAL_DIFF=<name of script> git diff ...
#
case $# in
1) "unmerged file $@, can't show you line numbers"; exit 1;;
7) ;;
*) echo "I don't know what to do, help!"; exit 1;;
esac

path=$1
old_file=$2
old_hex=$3
old_mode=$4
new_file=$5
new_hex=$6
new_mode=$7

printf '%s: ' $path
diff $old_file $new_file | grep -v '^[<>-]'

For details on "external diff" see the description of GIT_EXTERNAL_DIFF in the git manual page (around line 700, pretty close to the end).

这篇关于我可以让git diff只显示更改的文件名和行号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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