从git diff中排除一个目录 [英] Exclude a directory from git diff

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

问题描述

我想知道如何从Git diff中排除整个目录。 (在这种情况下/规格)。我正在使用git diff命令为我们的整个软件版本创建diff。然而,对规格的更改与此过程无关,只是令人头痛。现在我知道了我可以做的

  git diff previous_release..current_release app / 

这会为app目录中的所有更改创建diff,但不会在lib /目录中创建。有谁知道如何完成这项任务?谢谢!



编辑:我只想说清楚,我知道我可以将所有目录的参数串到最后,减去/ spec。我希望有一种方法可以真正排除命令中的单个目录。 解决方案

假设你使用bash,已启用扩展通配符( shopt -s extglob ),您可以从shell端处理:

  git diff previous_release current_release!(spec)

保存你不得不列出所有其他的东西。



或者shell不可知:

  git diff previous_release current_release --name-only | grep -v'^ spec /'\ 
| xargs git diff previous_release current_release -

您可以将其封装在单行shell脚本中以保存你必须重新输入参数。


I'm wondering how I can exclude an entire directory from my Git diff. (In this case /spec). I'm creating a diff for our entire software release using the git diff command. However the changes to the specs are irrelevant for this procedure, and just create headaches. now I know i can do

git diff previous_release..current_release app/

This would create a diff for all the changes in the app directory, but not for instance, in the lib/ directory. Does anyone know how to accomplish this task? Thanks!

Edit: I just want to be clear, I know I can just string the parameters of all of my directories on the end, minus /spec. I was hoping there was a way to truly exclude a single directory in the command.

解决方案

Assuming you use bash, and you've enabled extended globbing (shopt -s extglob), you could handle that from the shell side:

git diff previous_release current_release !(spec)

Saves you having to list all other things.

Or, shell-agnostic:

git diff previous_release current_release --name-only | grep -v '^spec/' \
    | xargs git diff previous_release current_release --

You could wrap that up in a one-liner shell script to save yourself having to retype the arguments.

这篇关于从git diff中排除一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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