git diff-仅显示更改的目录 [英] git diff - only show which directories changed

查看:157
本文介绍了git diff-仅显示更改的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法只列出已更改的目录?

Is there a way to list only the directories that were changed?

如果我在git根目录下,请说~/project

If I'm at the git root say, ~/project

我更改的文件是

~/project/subtool/file1

~/project/subtool/file2

~/project/subtool3/file1

我只想要

~/project/subtool

~/project/subtool3

推荐答案

您可以使用 git-diff --dirstat 参数一起使用.

You could use git-diff with the --dirstat parameter.

在您的情况下,假设您具有以下提交:

In your scenario, let's say you have the following commit:

$ git diff --name-status HEAD~1
M       subtool/file1
M       subtool/file2
M       subtool3/file1

它将产生以下输出:

$ git diff --dirstat=files,0 HEAD~1
  66.6% subtool/
  33.3% subtool3/

确保添加,0,否则默认情况下git diff仅显示更改至少3%的目录.我还选择了files,因为这是计算上最便宜的选项,而且您似乎也不在乎特定的更改.

Make sure to add ,0, otherwise git diff will by default only show directories with at least 3% changes. I also chose files as this is the computationally cheapest option and you do not seem to care about specific changes anyway.

如果您可以使用 sed 删除百分比值(您可能希望调整常规表情有点符合您的需求):

If you are able to use sed you can get rid of the percentage values (you may want to tweak the regular expression a bit to fit your needs):

$ git diff --dirstat=files,0 HEAD~1 | sed 's/^[ 0-9.]\+% //g'
subtool/
subtool3/

这篇关于git diff-仅显示更改的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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