Git Status - List only the direct subfolders with changes, not inner files

删除回忆录丶 提交于 2019-12-02 16:26:52

问题


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

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.

For example, this git command:

git status project_folder/wp-content/plugins

will result to:

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

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

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

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

Command such:

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


回答1:


try this:

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

awk '{print $2}' 

get filename from list

xargs -n 1 dirname 

extract dir from a full path

uniq

show only unique directories

uniq can be a little slower when you have many lines



来源:https://stackoverflow.com/questions/54193757/git-status-list-only-the-direct-subfolders-with-changes-not-inner-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!