我可以让git diff只显示更改的文件名和行号吗? [英] Can I make git diff only show the changed file names and line numbers?
问题描述
这里没有内置选项(我认为它也不是那么有用),但是它可以在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手册页面<
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屋!