将Git Diff限制为一项或多项功能? [英] Limit Git Diff to one or more functions?

查看:81
本文介绍了将Git Diff限制为一项或多项功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.git/info/attributes中设置了*.py diff=python.因此,Git知道函数边界在哪里. git diff -W甚至可以确保显示整个功能.

I set *.py diff=python in .git/info/attributes. So Git knows where function boundaries. git diff -W can even make sure the whole function is shown.

但是有没有办法将git diff的输出限制为仅一个特定函数(或多个函数)?

But is there a way to limit the output of a git diff to just a particular function (or more than one)?

(如果失败,我想这很糟糕...)

(Failing that, I guess it's awk...)

EDIT这对于git loggit rev-list也将很有用:不要向我展示所有修改views.py的提交,而是向我展示对其中某些功能进行修改的提交. (是的,在理想的世界中,views.py不会是由8个不同的开发人员经常修改的2000行巨兽...)

EDIT This would also be useful for git log and git rev-list: don't show me every commit that modifies views.py, show me commits that modify a certain function in it. (Yes, in an ideal world, views.py wouldn't be a 2000 line behemoth frequently modified by 8 different developers...)

推荐答案

好,感谢 Birei ,解决方案.

在该答案中使用awk脚本,并结合一些bash:

Use the awk script in that answer, combined with a bit of bash:

~/scripts/grit:

#!/bin/bash
cmd=$1
shift 1
if [ "$cmd" = "" ]; then
  git
# other commands not relevant to this question go here
elif [ $cmd = "funcdiff" ]; then
  git show "$1:$3" | awk -f ~/scripts/getfunc.awk -v f=$4 > /tmp/.tmp1
  git show "$2:$3" | awk -f ~/scripts/getfunc.awk -v f=$4 > /tmp/.tmp2
  git diff -W --no-index /tmp/.tmp1 /tmp/.tmp2 

else
  git $cmd $@
fi

示例用法:grit funcdiff 009e75 8b7a14 ./staging.py write_uploaded

这也可以作为git别名添加到〜/.gitconfig

This could also be added as a git alias in ~/.gitconfig

这篇关于将Git Diff限制为一项或多项功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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