Git 状态 - 仅列出有更改的直接子文件夹,而不是内部文件 [英] Git Status - List only the direct subfolders with changes, not inner files

查看:16
本文介绍了Git 状态 - 仅列出有更改的直接子文件夹,而不是内部文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用 Git 来组织版本控制并备份我在 Wordpress 中的所有 Web 文件.

I love using Git to organize version control and backup all my web files in Wordpress.

更新插件后,我想使用 git status 仅获取直接子文件夹中的更改列表.通常,如果执行 git status 将进行很长的更改,包括每个子文件夹的内部.我想要的是将结果限制在 plugins 目录中更改的子文件夹中.

After updating plugins, I'd like to get the list of changes only on the direct subfolder by using git status. Typically if doing git status will a very long line of changes including the inner of each subfolder. what I'd like is to limit the result to the subfolders with the changes inside the plugins directory.

例如这个git命令:

git status project_folder/wp-content/plugins

git status project_folder/wp-content/plugins

将导致:

plugins/wpml-translation-management/classes/translation-basket/
plugins/wpml-translation-management/classes/translation-dashboard/
plugins/acfml/assets/
plugins/acfml/classes/class-wpml-acf-attachments.php
plugins/wordpress-seo/js/dist/commons-921.min.js
plugins/wordpress-seo/js/dist/components-921.min.js

实际上,git 命令会生成一个非常长的行列表,如屏幕截图所示:

Actually, the git command will make a really long list of lines like on the screenshot:

我想知道的是只输出 git 命令:

What I would love to know is the git command to output only:

plugins/wpml-translation-management/
plugins/acfml/
plugins/wordpress-seo/

命令如下:

git status project_folder/wp-content/plugins --{display_only_direct_subfolders_with_changes}

git status project_folder/wp-content/plugins --{display_only_direct_subfolders_with_changes}

推荐答案

试试这个:

git status --porcelain | awk '{print $2}' | xargs -n 1 dirname | uniq

<小时>

awk '{print $2}' 

从列表中获取文件名

xargs -n 1 dirname 

从完整路径中提取目录

uniq

只显示唯一的目录

uniq 当你有很多行时可能会慢一些

uniq can be a little slower when you have many lines

这篇关于Git 状态 - 仅列出有更改的直接子文件夹,而不是内部文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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